在Python中如何划分两个输入值?

在Python中如何划分两个输入值?,python,variables,input,Python,Variables,Input,我正试图制作一个程序,将故事中的单词数量除以章节数量,从而得到每章的单词数量。以下是脚本: chapters = float(input('Enter the number of chapters. ')) words = float(input('Enter the number of words. ')) var1 = float(input(words / chapters)) 每次我运行它时,它允许我输入值,但在尝试计算后,我得到以下结果: Traceback (most recent

我正试图制作一个程序,将故事中的单词数量除以章节数量,从而得到每章的单词数量。以下是脚本:

chapters = float(input('Enter the number of chapters. '))
words = float(input('Enter the number of words. '))
var1 = float(input(words / chapters))
每次我运行它时,它允许我输入值,但在尝试计算后,我得到以下结果:

Traceback (most recent call last):


File "/Users/Hudson/Desktop/Fanfiction Word Calculator.py", line 2, in <module>
    words = float(input('Enter the number of words. '))
ValueError: could not convert string to float: '253,685'
回溯(最近一次呼叫最后一次):
文件“/Users/Hudson/Desktop/fanfinity Word Calculator.py”,第2行,在
words=float(输入('输入字数'))
ValueError:无法将字符串转换为浮点:“253685”

知道为什么吗?是因为数字太大吗?我已经一年没有使用Python了,所以我忘了怎么做:试一下253.685,而不是最后一行中的253685,你不需要输入。我修改了您的代码并运行了它,没有任何错误:

chapters = float(input('Enter the number of chapters. '))
words = float(input('Enter the number of words. '))
var1 = float(words / chapters)

在转换为float之前,请尝试删除逗号。我想您不需要在
var1=float(输入(单词/章节))
中再次输入。另请参见请不要回答打字错误问题。他们应该被删除,因为他们对任何人都没有帮助。很可能OP不想输入253.685个单词,但253685我否决了你的答案,但我这样做是错误的。但是,除非您进行编辑,否则我无法删除否决票:-/