2.17. ExercisesΒΆ

Evaluate the following numerical expressions in your head, then use the active code window to check your results:
5 ** 2
9 * 5
15 / 12
12 / 15
15 // 12
12 // 15
5 % 2
9 % 5
15 % 12
12 % 15
6 % 6
0 % 7
5 ** 2 = 25
9 * 5 = 45
15 / 12 = 1.25
12 / 15 = 0.8
15 // 12 = 1
12 // 15 = 0
5 % 2 = 1
9 % 5 = 4
15 % 12 = 3
12 % 15 = 12
6 % 6 = 0
0 % 7 = 0

What is the order of the arithmetic operations in the following expression. Evaluate the expression by hand and then check your work.

Optional. Many people keep time using a 24 hour clock (11 is 11am and 23 is 11pm, 0 is midnight). If it is currently 13 and you set your alarm to go off in 50 hours, it will be 15 (3pm). Write a Python program to solve the general version of the above problem. Ask the user for the time now (in hours), and then ask for the number of hours to wait for the alarm. Your program should output what the time will be on the clock when the alarm goes off.

It is possible to name the days 0 thru 6 where day 0 is Sunday and day 6 is Saturday. If you go on a wonderful holiday leaving on day number 3 (a Wednesday) and you return home after 10 nights you would return home on a Saturday (day 6). Write a general version of the program which asks for the starting day number, and the length of your stay, and it will tell you the number of day of the week you will return on.

Optional. Take the sentence: All work and no play makes Jack a dull boy. Store each word in a separate variable, then print out the sentence on one line using
print
.

Add parentheses to the expression
6 * 1  2
to change its value from 4 to 6.

Optional. The formula for computing the final amount if one is earning compound interest is given on Wikipedia as
Write a Python program that assigns the principal amount of 10000 to variable
P
, assign ton
the value 12, and assign tor
the interest rate of 8% (0.08). Then have the program prompt the user for the number of years,t
, that the money will be compounded for. Calculate and print the final amount aftert
years.

Write a program that will compute the area of a circle. Prompt the user to enter the radius and print a nice message back to the user with the answer.

Optional. Write a program that will compute the area of a rectangle. Prompt the user to enter the width and height of the rectangle. Print a nice message with the answer.

Write a program that will compute MPG for a car. Prompt the user to enter the number of miles driven and the number of gallons used. Print a nice message with the answer.

Optional. Write a program that will convert degrees fahrenheit to degrees celsius.

data1825: Piece together the code so that a user is asked for two numbers, and then the sum of those two numbers is printed out.num_one = input("Please enter your first number: ")  num_two = input("Please enter your second number: ")  sum_of_input = int(num_one) + int(num_two)  print(sum_of_input)

data1827: Write a program that will convert gallons to liters. This program will also need to get input from a user to see how many gallons should be converted and the result should be printed to the user.user_gallons = input("How many gallons should be converted?: ")  num_gallons = int(user_gallons)  liters = num_gallons * 3.785  print("Number of liters: " + str(liters))

data1829: Write a program that will convert table spoons to teaspons. This program will also need to get input from a user to see how many tablespoons should be converted and the result should be printed to the user.user_tablespoons = float(input("How many tablespoons should be converted?: "))  teaspoons = user_tablespoons * 3  print("Number of teaspoons: " + str(teaspoons))