Input:
Output:
We will now create a program with purpose. The user will type their name, and we will use the name to greet them. To do this we'll take input and combine it with other strings to generate output.
Change your program output to a different message. Make it longer. You
can even use input
more than once, for example, "Hello,
Susan! Wow, Susan is a great name. Reminds me of this movie star..."
Input:
Output:
Let's incorporate math operations. The user will now enter a distance in kilometres and the program will output the distance in miles. 1 km equals 0.62 miles.
Change myOutputValue
to see the calculation on screen.
Try changing distanceInKm
to see new conversions. To let
the user input distances, assign the value of input
to
distanceInKm
.
Input:
Output:
convertKmToMiles
return
statements from the examples. What
happens and why? What does the return
statement do and
how does it work?
distanceInKm
parameter from the function
definition. What happens and why? Replace the parameter afterward.
distanceInKm
to another name
everywhere. What happens and why? Change the name back to
distanceInKm
afterward.
Input:
Output:
Two trains are leaving to Tokyo. Train 1 is traveling 200kph, and will reach Tokyo in 2 hours. Train 2 is newer and can travel faster, but is delayed due to a signalling fault.
Build a program for Train 2's conductor to calculate how fast Train 2 needs to travel to arrive at Tokyo at the same time as Train 1, based on how long it was delayed. Output the speed in kph.
Input:
Output:
A user can enter the number of minutes past 1pm and the app will calculate the angle between the hour and minute hand. You are free to decide how else your clock will work: if the minute hand moves in 5 minute increments or moves every second, etc.
Input:
Output: