Chapter 2 Variables Exercises

by Elliott Hauser

19 Jan 2016

Submit a well-formatted pull request to our class blog with embedded Trinket programs for the below three exercises from Chapter 2 (use these instead of the ones in the book - I added a few explanations). Complete these on your own, using only the materials in Chapter 2. Do not look at other students’ submissions until after you’ve completed your work.

After your programs are done, check other students’ work and other resources online if you had questions. Include a reflection about what you think you’ve learned and any concepts that are still fuzzy to you. Did you encounter frustrating situations? Did you feel a lightbulb turn on?


Exercise 2: Write a program that uses input to prompt a user for their name and then welcomes them.

Here’s a sample run of the program. The user types ‘Chuck’ and presses enter.

Enter your name: Chuck
Hello Chuck

Exercise 3: Write a program to prompt the user for hours and rate per hour to compute gross pay.

Here’s a sample run of the program. The user types 35 Enter, then 2.75 Enter.

Enter Hours: 35
Enter Rate: 2.75
Pay: 96.25

We won’t worry about making sure our pay has exactly two digits after the decimal place for now. If you want, you can play with the built-in Python round function to properly round the resulting pay to two decimal places.

Exercise 5: Write a program which prompts the user for a Celsius temperature, convert the temperature to Fahrenheit, and print out the converted temperature.

You can compare your temperature converter program’s output with Google.

Elliott Hauser is a PhD Student in information science at UNC Chapel Hill. He's hacking education as one of the cofounders of Trinket.io. Find Elliott Hauser on Twitter, Github, and on the web.