西150 2023-07-26 23:56 采纳率: 33.3%
浏览 8
已结题

关于#python#温度转化的问题:SyntaxError: unexpected EOF while parsing

#小白1.3实例练习python温度转换一直无法运行

#老师演示的代码如下

img

我写的如下:

#tempconvert.py
TempStr = input("temperature value with signs:")
if TempStr[-1] in ['F','f']:
    C = (eval(tempstr[0:-1]) - 32)/1.8
    print("the converted temperature is{:.2f}C".format(C))
elif TempStr[-1] in ['C','c']:
    F = 1.8*eval(tempstr[0:-1]) + 32
    print("the converted temperature is{:.2f}F".format(F))
else:
    print("filed to output")

因为反复修改还是运行不成功,不知道是不是输入法的问题,就把里面的一些描述改成全英文了,甚至还直接复制了他人写的代码试运行,也不行
然而报错一直如下

Python 2.7.16 (v2.7.16:413a49145e, Mar  4 2019, 01:30:55) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> 
===================== RESTART: D:/python/tempconvert.py =====================
temperature value with signs:85f

Traceback (most recent call last):
  File "D:/python/tempconvert.py", line 2, in <module>
    TempStr = input("temperature value with signs:")
  File "<string>", line 1
    85f
      ^
SyntaxError: unexpected EOF while parsing
>>> 

请求解答是什么问题

  • 写回答

4条回答 默认 最新

  • a5156520 2023-07-27 08:49
    关注

    我这里测试将第4行和第7行的tempstr 改为TempStr,程序正常运行。

    测试如下:

    
    
    #tempconvert.py
    TempStr = input("temperature value with signs:")
    if TempStr[-1] in ['F','f']:
        # 将tempstr 改为TempStr
        C = (eval(TempStr[0:-1]) - 32)/1.8
        print("the converted temperature is {:.2f}C".format(C))
    elif TempStr[-1] in ['C','c']:
        # 将tempstr 改为TempStr
        F = 1.8*eval(TempStr[0:-1]) + 32
        print("the converted temperature is {:.2f}F".format(F))
    else:
        print("filed to output")
     
    
    
    

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(3条)

报告相同问题?

问题事件

  • 系统已结题 8月4日
  • 已采纳回答 7月27日
  • 修改了问题 7月27日
  • 创建了问题 7月26日

悬赏问题

  • ¥15 stm32u535芯片usb hid custom类接收数据有问题
  • ¥20 quartus功能仿真
  • ¥15 传染病最优控制问题,控制为什么没起作用
  • ¥15 ue5.3 pico打包失败 求帮助
  • ¥15 请教,这是用chatgpt写的CAD LISPD脚本,需求是画一个由双直线组成的矩形
  • ¥50 微信小程序 成功包奶茶啊
  • ¥15 计算机博弈的六子棋代码
  • ¥15 在Fetch API中传送的参数为何不起作用?
  • ¥15 问题遇到的现象和发生背景 360导航页面千次ip是20元,但是我们是刷量的 超过100ip就不算量了,假量超过100就不算了 这是什么逻辑呢 有没有人能懂的 1000元红包感谢费
  • ¥30 计算机硬件实验报告寻代