-1

I'm trying to make a program that would divide the amount of words in a story by the amount of chapters in order to get the amount of words per chapter. Here is the script:

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

Everytime I run it, it allows me to enter the values, but after trying to calculate, I get this:

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'

Any idea why? Is it because the number is too big? I haven't used Python in a year, so I forgot how to do this :p

Amit
  • 19,780
  • 6
  • 46
  • 54
Jason Smith
  • 1
  • 1
  • 1
  • try removing the comma before casting to float – akgill Apr 07 '15 at 17:21
  • 2
    I guess you don't need a input again in `var1 = float(input(words / chapters))` – Amit Apr 07 '15 at 17:22
  • See also [how to convert number with comma for thousands](http://stackoverflow.com/questions/1779288/how-do-i-use-python-to-convert-a-string-to-a-number-if-it-has-commas-in-it-as-th) – Peter Wood Apr 07 '15 at 17:36

2 Answers2

0

in last line you don't need input. I modified your code and run it without any error:

chapters = float(input('Enter the number of chapters. '))
words = float(input('Enter the number of words. '))
var1 = float(words / chapters)
Sara Santana
  • 1,001
  • 1
  • 11
  • 22
  • I downvoted your answer but I was wrong in doing so. However I cannot remove the downvote unless you make an edit :-/ – Tim Apr 07 '15 at 21:04
-2

Try 253.685 instead of 253,685