Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Whats Wrong!?
#4
(May-13-2020, 07:46 PM)buran Wrote: == is equality, = is assignment. fix it on lines 5 and 7
thank you so much it worked!!

(May-13-2020, 07:56 PM)deanhystad Wrote: Nested if's are a thing to avoid. For a problem like this it often works best to test for all the bad and if you get past that assume the input is good.
if not too_young < age < too_old:
    print('We don't like babies or or old people')
elif salary < 35,000:
    print('Get a decent job!')
elif have_id.lower() != 'y':
    print('another demeaning remark')
Better yet, don't ask further questions if they are already ineligible.
def eligibility():
    if input('Do you have a valid license? ').lower() != 'y':
         print('Sorry, a valid license is required.')
         return False
    if int(input('What is your age? ')) > 35:
         print('Sorry, we only accept applicants 35 or younger')
         return False
    # more tests
    print('Your are eligible')
    return True
Thank you for the advise! Really appreciate it!
Reply


Messages In This Thread
Whats Wrong!? - by rjay81 - May-13-2020, 07:43 PM
RE: Whats Wrong!? - by buran - May-13-2020, 07:46 PM
RE: Whats Wrong!? - by deanhystad - May-13-2020, 07:56 PM
RE: Whats Wrong!? - by rjay81 - May-13-2020, 08:02 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Am I wrong or is Udemy wrong? String Slicing! Mavoz 3 2,885 Nov-05-2022, 11:33 AM
Last Post: Mavoz
  Whats wrong with the elif? inunanimous93 3 2,598 Nov-30-2020, 03:58 AM
Last Post: deanhystad
  Can u see this code and tell whats wrong with it? AhmadKamal 14 5,675 Apr-29-2020, 11:09 AM
Last Post: jefsummers
  python gives wrong string length and wrong character thienson30 2 3,133 Oct-15-2019, 08:54 PM
Last Post: Gribouillis
  Whats a good design/approach? hshivaraj 1 1,864 Sep-16-2019, 01:44 AM
Last Post: snippsat
  elevator simulator...whats the wrong at this code? tasos710 5 6,053 Jun-11-2019, 01:38 AM
Last Post: micseydel
  whats the difference between sys.exit() and break? mitmit293 1 4,192 Jan-27-2019, 09:46 PM
Last Post: ichabod801
  Whats wrong with this code? student1 1 2,518 May-18-2018, 04:19 PM
Last Post: skorpius_
  I have no clue whats wrong... Jack_03 1 2,905 Sep-28-2017, 05:36 PM
Last Post: nilamo
  Whats wrong with line 12? brimalm 2 3,275 Sep-11-2017, 12:23 PM
Last Post: brimalm

Forum Jump:

User Panel Messages

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