Edit: disclaimer: You can utilize the information this post provides safely now, proper edits were made after the comments (again).
I should clarify that using eval
can be risky in other environments since it allows arbitrary code to be executed. Be sure to check out the commented lines in the code below.
don't use eval
in your code. Ever (unless you know what you're doing and have no choice).
By default the input returned from calling input()
is a string. Call eval
/ float
/ int
on the input to convert it to a number to be able to perform arithmetic operations on input.
# you could use whatever function you want for conversion, but remember the use-cases for each one
# calling eval on random strings is dangerous in non-testing environments since it can cause any valid code the user wants at all to be run
hourlyWage = float(input('Hourly Wage?'))
weeklyHours = float(input('Weekly Hours?'))
weeklyWage = hourlyWage * weeklyHours
print(weeklyWage)