Python Forum

Full Version: bad input line 3 how t fix it
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hrs = input("Enter Hours:")
h = float(hrs)
if h <= 40:
rate = 1.5
print(" h * rate")
elif h > 40.0 :
rate = 10.5
print(" h * rate")
remove the quotes on print

hrs = input("Enter Hours:")
h = float(hrs)
if h <= 40:
    rate = 1.5
    print(h * rate)
elif h > 40.0 :
    rate = 10.5
    print(h * rate)
shorter version

hrs = float(input("Enter Hours:"))
print(hrs * 1.5) if hrs <= 40 else print(hrs * 10.5)
(Aug-27-2020, 01:42 PM)Axel_Erfurt Wrote: [ -> ]shorter version

hrs = float(input("Enter Hours:"))
print(hrs * 1.5) if hrs <= 40 else print(hrs * 10.5)

Oh I like this game!
hrs = # blah
print(hrs * (1.5 if hrs <=40 else 10.5))
Or we can use indexing, knowing True=1 and False=0 (I don't like this version, though, it's not immediately obvious what's going on):
hrs = # blah
print(hrs * (1.5, 10.5)[hrs > 40])
OR! All in one line, for a terribly hard to read version:
print( (hrs := float(input("Hours? "))) and (hrs * (1.5, 10.5)[hrs > 40]))