Python Forum
bad input line 3 how t fix it
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
bad input line 3 how t fix it
#1
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")
Reply
#2
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)
Reply
#3
(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]))
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Receive Input on Same Line? johnywhy 8 706 Jan-16-2024, 03:45 AM
Last Post: johnywhy
  How to input & output parameters from command line argument shantanu97 1 2,555 Apr-13-2021, 02:12 PM
Last Post: Larz60+
  How to make input come after input if certain line inserted and if not runs OtherCode Adrian_L 6 3,326 Apr-04-2021, 06:10 PM
Last Post: Adrian_L
  Multi-line console input lizze 4 2,351 Dec-26-2020, 08:10 AM
Last Post: lizze
  Line charts error "'isnan' not supported for the input types," issac_n 1 2,400 Jul-22-2020, 04:34 PM
Last Post: issac_n
  Taking Multiple Command Line Argument Input bwdu 6 4,023 Mar-29-2020, 05:52 PM
Last Post: buran
  How to make input goto a different line mxl671 2 2,452 Feb-04-2020, 07:12 PM
Last Post: Marbelous
  command line input (arg parse) and data exchange Simba 7 4,322 Dec-06-2019, 11:58 PM
Last Post: Simba
  Multiple Line Input helenaxoxo 4 2,920 Dec-02-2019, 11:06 PM
Last Post: helenaxoxo
  A question about subprocess taking input from command line and returning output! Aurimas 8 5,166 May-15-2019, 04:02 PM
Last Post: Aurimas

Forum Jump:

User Panel Messages

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