无法将数字转换为浮点数 [英] Can't convert a number to a float

查看:105
本文介绍了无法将数字转换为浮点数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为Python的新手,我正在尝试解决一项家庭作业问题,但我不明白自己做错了什么.我下面有代码和错误消息,希望有人可以告诉我我哪里出错了.

I'm trying to solve a homework problem as an extreme novice to python, and I don't understand what I'm doing wrong. I have the code and error message below, hoping that someone can tell me where I went wrong.

英里输入尝试10、50,然后是100.有效. Mpg是20.0.也可以. GP输入为3.1599,这给了我这个错误.不知道为什么.

The miles input tries 10, 50, then 100. Which works. Mpg is 20.0. Also works. gp input is 3.1599, which gives me this error. Not sure why.

miles = float(input())  
mpg = float(input())
gp = float(input())
price = (miles*1.0/mpg)*gp
print(price)

回溯(最近通话最近): 在第3行的文件"main.py"中 gp = float(input()) EOFError:读取行时出现EOF

Traceback (most recent call last): File "main.py", line 3, in gp = float(input()) EOFError: EOF when reading a line

推荐答案

`mpg = float(input('Enter miles per gallon:'))
 gp = float(input('Enter the gas price:'))
 price = (10*1.0/mpg)*gp print(price) 
 price = (50*1.0/mpg)*gp print(price) 
 price = (400*1.0/mpg)*gp print(price)`      

这就是答案,已解决

这篇关于无法将数字转换为浮点数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆