Python Forum
IF ELSE Homework Question
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
IF ELSE Homework Question
#1
I have the code written to return the below values based on the age a user inputs. I am struggling to come up with an ELSE
statement that will only allow one print statement to be generated. Here is the code that I have thus far.

def main():

    numb = int(input('Please enter your age: '))   
    if numb < 1:
        print('Invalid')
    if numb < 18:
        print('Too Young')
    if numb < 65:
        print('Still Working')
    if numb > 65:
        print('Retired')

main()
Reply
#2
you need to use elif, not else.
you can have single if, [optional] multiple elif and [optional] single else
Note that currently your conditions don't cover case where numb is 65
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Homework help:While Loops question Midhat_School 6 3,181 Jul-26-2020, 10:23 AM
Last Post: pyzyx3qwerty
  Python Homework Question OrcDroid123 1 2,412 Sep-01-2019, 08:44 AM
Last Post: buran
  Homework question dmhhfm 4 13,435 Apr-10-2019, 07:22 AM
Last Post: DeaD_EyE
  Beginner Python Homework Question (Calculate Gross Pay) matchamochi7 4 5,775 Nov-02-2018, 01:06 PM
Last Post: buran
  yet another homework question HakolYahol 16 7,856 Sep-27-2018, 04:52 PM
Last Post: gruntfutuk
  python in JES homework question, lsteffen 1 3,048 Feb-11-2018, 05:52 PM
Last Post: Taco_Town

Forum Jump:

User Panel Messages

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