我还想加入数值的判断, C1>40时, print("sorry, the number is out of scope")
时间: 2024-04-16 20:28:10 浏览: 13
Sure! I've added the condition to check if the input value is greater than 40. If it is, it will print the message "Sorry, the number is out of scope". Here's the updated code:
```python
print("Suppose you have an American friend who doesn't know the difference between Celsius and Fahrenheit.")
print("You have to do the simple calculation for him.")
print("Tell me what is the weather now in Celsius. I will let you know the Fahrenheit number.")
print("Enter 'q' to quit")
while True:
C1 = input(">> ")
if C1 == 'q':
print("Byebye.")
break
try:
C1 = int(C1)
F = int(9/5*C1+32)
if C1 > 40:
print("Sorry, the number is out of scope.")
else:
print(F, "Fahrenheit")
except ValueError:
print("Please input a valid number.")
```
Now, when the input value is greater than 40, it will display the message "Sorry, the number is out of scope". Otherwise, it will convert and print the temperature in Fahrenheit.
Let me know if you have any other questions!