🚀 Basics Day 1: Pre-Class Exercises 🚀

Pre-Class In-Class

Default Template (Our First Program)

Input:


Output:

Greeting Program (Our First Program)

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:

Metric Conversion Program (Our First Program)

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:

Base: Run Example Code (Functions I)

  1. Duplicate and run the code from the Functions I module
  2. Paste the other function examples in instead of convertKmToMiles
  3. Remove the return statements from the examples. What happens and why? What does the return statement do and how does it work?
  4. Remove the distanceInKm parameter from the function definition. What happens and why? Replace the parameter afterward.
  5. Change the variable name distanceInKm to another name everywhere. What happens and why? Change the name back to distanceInKm afterward.

Input:


Output:

Comfortable: Train Speed (Functions I)

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:

More Comfortable: Clock (Functions I)

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: