-2

I'll take any input. Just started programming in Python and can't solve this error.

My simple code:

hourlyWage = input('Hourly Wage?')
weeklyHours = input('Weekly Hours?')
weeklyWage = hourlyWage * weeklyHours
print(weeklyWage)

The error:

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

I create two variables that a User can input, when I try to get the product of the two variables I get an error. Any help is appreciated.

funie200
  • 3,294
  • 5
  • 19
  • 31
Jeff
  • 13
  • 1
  • Use `hourlyWage = int(input('Hourly Wage?'))` etc – ssp Dec 14 '20 at 23:26
  • 2
    Input will always be string. You need to conert it to integer. Use `int(hourlyWage)` – Joe Ferndz Dec 14 '20 at 23:26
  • 6
    Being new is no excuse, your title should always have something to do with your actual question. – Mark Ransom Dec 14 '20 at 23:27
  • https://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-response : A sking the user for input until they give a valid response I liked this one very much – pippo1980 Dec 14 '20 at 23:44

2 Answers2

0

The input function returns a string, so you need to convert it to a float like this:

hourlyWage = float(input('Hourly Wage?'))
weeklyHours = float(input('Weekly Hours?'))
weeklyWage = hourlyWage * weeklyHours
print(weeklyWage)

Did you notice float()? That converted your string to a float. Now your program will work.

Lakshya Raj
  • 1,094
  • 4
  • 20
-1

Convert it to int first. (input() returns a string)

hourlyWage = int(input('Hourly Wage?'))
RvdK
  • 19,128
  • 3
  • 59
  • 105