-2

When I run it in Python 3.6 environment, I'll get an error saying; '>' not supported between instances of 'str' and 'int'

hours_Worked = input ("Enter the hours worked\n")
rate = 25.00
if hours_Worked > 40:
    grosspay = (40*rate) + ((hours_Worked-40) + (rate*1.5))
if hours_Worked <= 40:
        grosspay = hours_Worked * rate
print("Gross Pay: ", str(grosspay))

I can get the correct output in python 2.7 after changing the input seeking syntax.

What is wrong with this code? I don't understand!! I got to know that the error is with if-statement.

I'm new to python. Please help me.

Sayse
  • 42,633
  • 14
  • 77
  • 146
Chaaru Manjuraj
  • 53
  • 1
  • 10
  • `input()` returns a string in Python 3. You have to convert it with `float()` or `int()` into a number. – Mr. T Mar 27 '18 at 08:03

1 Answers1

0

You need to convert the input to int. By default it returns a string.

Ex:

hours_Worked = int(input("Enter the hours worked\n"))
Rakesh
  • 81,458
  • 17
  • 76
  • 113