Lifestyle
Lifestyle

Reputation: 9

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

I'm a complete newbie programmer, infact I just started today.. I was trying to follow a basic guide on how to calculate gross pay and I keep coming up with the following error "TypeError: can't multiply sequence by non-int of type 'float' on line 5"

Here is the code below

hrs = input("Enter Hours:")
Rate = float(input("Enter Rate of Pay:"))
pay = hrs * Rate
print ("Pay:", pay)

Any help on this would be greatly appreciated

Upvotes: 0

Views: 3296

Answers (3)

Jay Dutt
Jay Dutt

Reputation: 1

what you're doing here is multiplying a string type with float which is resulting in the error. to fix this, you can- hrs = int(input("Enter Hours:")) Rate = float(input("Enter Rate of Pay:")) pay = hrs * Rate print ("Pay:", pay)

Upvotes: 0

Matt Kuda
Matt Kuda

Reputation: 1

You need to define the variable type of "hrs"

hrs = float(raw_input("Enter Hours:")
Rate = float(raw_input("Enter Rate of Pay:"))
pay = hrs * Rate
print ("Pay:", pay)

Upvotes: 0

Evgeni Genchev
Evgeni Genchev

Reputation: 37

In your code rate is float but hrs is not. You are basically multiplying string with float. So hrs should be casted as float too.

hrs = float(input("Enter Hours:"))
Rate = float(input("Enter Rate of Pay:"))
pay = hrs * Rate
print ("Pay:, pay)

P.S. Have in mind PEP8 and use only lowercase for variable names unless there are const (then use upper).

Upvotes: 1

Related Questions