Python程序测试水状态为celcius提供了错误答案

galagaguy90

该程序应该有两个输入,度的单位是F或C,然后是温度,然后打印出水的状态。无论我为C投入多少(除了1000),我都得到答案是液体,从不冷冻或气体。这是我的代码:

print("Do you use Fahrenheit (F) or Celcius? (C)")
degreeUnit = (input("Enter F or C:")).upper()
temp = int(input("What is the temperature of the water?"))
if degreeUnit == "F" and temp <=32: #checking if unit is F and if water is frozen
    print("The water is frozen.")
elif degreeUnit == "F" and temp >= 212: #water freezes at 32F is gas at 212 is it gas?
    print("The water is a gas")
elif degreeUnit == "F" and temp >=33 or temp <=211:
    print("The water is a liquid.")
elif degreeUnit == "C" and temp <=0: #water freezes at 0C
    print("The water is frozen.")
elif degreeUnit == "C" and temp >=100: #water is gas at 100C
    print("The water is a gas.")
elif degreeUnit == "C" and temp >=1 or temp <=99:
    print("The water is a liquid.")
else:
    print("Please try again, something went wrong.")
input()

我觉得自己缺少明显的东西,但是我不断地阅读它,看不到我在做什么错。任何帮助表示赞赏。

杰夫·埃伦

如果您经常进水,则应检查是否有液体。真的是您想要的吗?(提示,不是)。检查最后一个elif语句的逻辑,您对于'F'也有相同的错误(自由单位:-D)

您可能还会发现,加入括号以查看您的逻辑会有所帮助:

a=False
b=True
c=True
a and b or c
>>>True
a and (b or c)
>>>False

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

素数程序给出错误答案

Prime Generator程序SPOJ错误答案

尝试运行“ ng测试”时,没有提供MatSnackBar错误的提供程序

测试时为类提供了错误类型的ID

错误:没有HttpService的提供程序!在业力测试中

Upwork C ++测试答案错误

使用TestBed进行测试:没有提供StatusBar错误的提供程序

测试#2失败。错误的答案

Angular 5-Jasimine测试-错误:NgModule'DynamicTestModule'的提供程序无效-仅允许提供程序和类型的实例

角度测试错误-NullInjectorError:TrimInputDirective没有提供程序

Python程序给我错误的答案

数字总和程序,得到错误的答案

ADFS SAML身份提供程序重定向到状态为“响应者”的服务提供程序

错误:为函数__THROW __asm提供了初始化程序

使用Azure KeyVault为连接字符串添加会话状态提供程序

Beta测试,外部测试状态为无效

测试是正确的,但答案仍然是错误的

带有剃刀语法的ASP.NET vbhtml为DateTime.Now.DayOfWeek提供了错误答案?

测试用例:各种文件:错误答案

Caesar Cipher:为什么我的程序返回错误的答案,当用作测试的打印值之间有正确的值时?

检查谜语答案的 Python 程序

Laravel 应用程序为 foreach() 错误提供的参数无效

当测试结果失败时,容器状态为错误

尝试运行 Specflow 测试但返回错误 - 单元测试提供程序已指定

反应表单 onChange 处理程序为错误的键设置状态

如何在 React 中为单个正确或错误的答案状态返回文本

使用提供程序测试组件

十进制到罗马的转换程序在 Python 中给出错误答案

Python错误答案输入