Python Forum
TypeError: can't multiply sequence by non-int of type 'str'
Thread Rating:
  • 2 Vote(s) - 4.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError: can't multiply sequence by non-int of type 'str'
#1
Hello, I'm new to Python and I'm trying to type some code for an assignment.  It seemed relatively easy but it turned out being a hassle.
I get the following error with the running of the code:
Error:
TypeError: can't multiply sequence by non-int of type 'str'
Here is my code:
hours = input('Enter Hours:')
float(hours)
rate = input('Enter Rate:')
float(rate)
pay = hours * rate
print('Pay:' + pay)
The error is occurring at the line:
pay = hours * rate
Can someone please tell me what is wrong?  I just can't seem to find the error.
Reply
#2
These lines do nothing:
float(hours)
float(rate)
What you mean is:
hours = float(hours)
rate = float(rate)
Reply
#3
Thanks, but now I have a different error:
TypeError: must be str, not float
Reply
#4
Yep, now this line is wrong:
print('Pay:' + pay)
You can't add a string and a float.
print("Pay: {}".format(pay))
Reply
#5
I am also new to python..
this line has error
print('Pay:' + pay)
try this
print('Pay:' + str(pay))

User has been warned for this post. Reason: Resurrect long answered threads
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  TypeError: unsupported operand type(s) for /: 'str' and 'int' enderfran2006 1 2,648 Oct-01-2020, 09:41 AM
Last Post: buran
  TypeError: can't multiply sequence by non-int of type 'complex' FeverDream 2 12,756 Jul-12-2018, 11:08 PM
Last Post: DeaD_EyE
  TypeError: can't multiply sequence by non-int of type 'str' Beatenberg 12 13,674 Oct-10-2017, 10:14 PM
Last Post: Beatenberg
  python!TypeError: can't multiply sequence by non-int of type 'float' shaywune 2 9,493 Sep-24-2016, 04:33 PM
Last Post: shaywune

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020