Answer to Question #207560 in Python for dhrsn

Question #207560

Write a Python program using lists, function and loops that will prompt a user to enter a temperature as an integer. Your program will print "it is hot" if the temperature is over 100, "it is cold" if the temperature is under 60, and "it is just right" if the temperature is between 61 and 99 inclusive. The program continues to ask for temperatures, and evaluates them as above, until the user enters a temperature of 0 (to exit the program). An example of the anticipated program is shown below: Please enter a temperature: 95 It is just right. Please enter a temperature: 110 It is hot. Please enter a temperature: 32 It is cold. Please enter a temperature: 0 Good bye! 



1
Expert's answer
2021-06-16T05:23:04-0400
output = ['It is hot', 'It is cold', 'It is just right', 'Good bye']
def temp():
    t= int(input('Please Enter temperature:'))
    if t >100:
        result = output[0]


    elif t == 0:
        print(output[3])
        exit()
    elif t < 60:
        result= output[1]
    
    else:
        result = output[2]
    print (result)
while True:
    temp()
    

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS