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
#ex_02_ch2
inp_name = input("Enter your name: ")
print("Hello", inp_name)
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 builtin Python round function to properly round the resulting pay to two decimal places.
#ex_03_ch2
inp_hours = input("Enter hours: ")
inp_rate = input("Enter rate: ")
fl_hours = float(inp_hours)
fl_rate = float(inp_rate)
pay = fl_hours * fl_rate
print("Pay: ", pay)
Exercise 4: Assume that we execute the following assignment statements:
height = 12.0
width = 17
For each of the following expressions, write the value of the expression and the type (of the value of the expression).
1. width//2
2. width/2.0
3. height/3
4. 1+2/5
Use the Python interpreter to check your answers.
#ex_04_ch2
height = 12.0
width = 17
a = width//2
b = width/2.0
c = height/3
d = 1+2/5
print("width//2: ", a, type(a))
print("width/2.0: ", b, type(b))
print("height/3: ", c, type(c))
print("1+2/5: ", d, type(d))
Exercise 5: Write a program which prompts the user for a Celsius temperature, convert the temperature to Fahrenheit, and print out the converted temperature.
#ex_05_ch2
inp_temp = input("Enter temperature in Celcius: ")
fl_temp = float(inp_temp)
temp_in_F = (fl_temp * 9/5 ) + 32
print("Temperature in Fahrenheit: ", temp_in_F, "°F")