This exercise will help students understand more about List, Inputs, IF and ELSE and Loops:
- Create a List of Integer: 1,2,3,4,5,6
- Multiply the first and 3rd element of the list and assign the result to variable “result”.
- Print the “result” to the shell.
- Create a “for loop” that will print “. Hi there” 6 times like the following
0. Hi there 1. Hi there 2. Hi there 3. Hi there 4. Hi there 5. Hi there
- Get input from shell: “What grade are you in? ”
- If user enter ‘1’ or ‘1st’ or ‘first’ or ‘pertama’ then print ‘You are learning to read.’
- If user enter ‘2’ or ‘2nd’ or ‘second’, then print ‘You are learning multiplication.’
- If user enter ‘3’ or ‘3rd’ or ‘third’, then print ‘You are learning shapes.’
- Else, then print ‘I don’t know what you are studying.’
- Create a function, “hello_world”, with no parameter and inside the function, it will print “Hello World”. Call the function.
- Create a function, “greeting”, with one parameter, “name”. Inside the function, print to the shell the combination of the word “Greeting ” and the name parameter. Call the function like this “greeting(‘Gamas’)” . The result should be “Greeting Gamas” in the shell.
- Create a function, “combine_words”, with 3 parameters. Inside the function, print the combination of all three parameters. Call the function like this: “combine_words(‘Hello ‘, ‘Mr. ‘, ‘Gamas.’)” . This will print ‘Hello Mr. Gamas’ to the shell.
- Create a function with return value, “convert_miles_to_km”, with 1 parameter: miles.
- Inside the function, convert the parameter “miles” into the “km” value. There are 1.6 km in one mile. Return the conversion result or the km value.
- Outside the function:
- Ask user in the shell “Enter number of miles: “
- Get the user input and call the function and pass the user input as the parameter.
- Print “There are {result of the function} kms in {user_input} miles”.