Multiplying user input by a float in python

Question:
Cant multiply user input by a float
Repl link:

hours = input("How many hours?")
hours = (hours * 0.25)

of course doing this code gets the error:

TypeError: can't multiply sequence by non-int of type 'float'

When you use the input in Python the result will be a string. To make it a number put Int() around it.

5 Likes

Remember Python is case-sensitive, the i in int needs to be lowercase.

4 Likes

Thanks for adding that. Never used it so wouldn’t know lol. Thats what happens when a JS dev answered a python question (looking at you Number())

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.