Opening the book…
Exercise 2: Write a program that uses input to prompt a user for their name and then welcomes them.
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.
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.
%%python3 #Use this space to write and run your code #Save this code for a later exercise!
Exercise 4: Assume that we execute the following assignment statements:
width = 17
height = 12.0
For each of the following expressions, write the value of the expression and the type (of the value of the expression).
width//2width/2.0height/31 + 2 * 5
%%python3 #Use this space to check your answers
Exercise 5: Write a program which prompts the user for a Celsius temperature, convert the temperature to Fahrenheit, and print out the converted temperature.
%%python3 #Use this space to write and run your code
- In Python 2.0, this function was named
raw_input.↩ - See http://en.Wikipedia.org/wiki/Mnemonic for an extended description of the word "mnemonic".↩
This page titled 2.E: Variables, Expressions, and Statements (Exercises) was last modified on Tue, 01 Dec 2020 03:50:49 GMT and is shared under a CC BY-NC-SA 4.0 license and was authored, remixed, and/or curated by Chuck Severance via source content that was edited to the style and standards of the LibreTexts platform.
The book could not be loaded just now.