In: Computer Science
Question 9: pi = 3.14159 formatted = _______.format(pi) print("Pi day sale! All pies", formatted, "off.")
Fill in the blank so that the following program prints:
Pi day sale! All pies $3.14 off.
Question 11:
Complete the following program that keeps asking for a price until the user just presses the enter key. Assume the user only enters floating point values. The program totals the values entered by the user and print out the result.
total = 0 while True: ans = input("Enter a number or nothing when done:") if _____________ : break total = _________________ print("The total is",total)
Question 12:
Complete the following fragment of a program that asks for an integer from 1 through 9 (including 1 and 9). Assume the user only enters integers. The program should keep asking until the user enters a number in range.
while True: x = int(input("Enter a positive single digit integer:")) if _____________ : break print("You chose", x)
Question 13:
Fill in the blanks with Boolean comparisons to map the following temperatures to messages. Avoid the logical operators and/or/not.
temp is 55 degrees or lower is 'Cold' temp is 88 degrees or higher is 'Hot' temp between 55 and 88 degrees is 'Fair'
if temp ______________: print("Hot") elif temp ______________: print("Fair") else: print("Cold")
Have a look at the below code. I have put comments wherever required for better understanding.
Question 9:
Question 11:
Question 12:
Question 13:
pi = 3.14159
formatted = "${:.2f}".format(pi) # format the value
print("Pi day sale! All pies", formatted, "off.")
total = 0
while True:
ans = input("Enter a number or nothing when done:")
if (ans==""):
break
total = total + float(ans)
print("The total is",total)
while True:
x = int(input("Enter a positive single digit integer:"))
if x not in range(1,10):
break
print("You chose", x)
temp = int(input("Enter the tempearture: "))
if temp>=88:
print("Hot")
elif temp in range(56,88):
print("Fair")
else:
print("Cold")
Happy Learning!