Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Whats Wrong!?
#1
Hello, I am new to programming. I need help in understanding what i am doing wrong or what is the error in this code.
Basically the program is an eligibility checker *practice purposes, following a textbook*. user will enter their information age, if they have id and salary. depending on their inputs the code will generate a message stating if they are eligible.

print("Welcome to our online elegibility checker!")
age = int(input("Please enter your age:"))
have_id = input("Do you have valid id: [Y/N]:")
if have_id.lower()=="y":
    have_id == True
else:
    have_id == False
salary = int(input("What is your annual salary:$"))
if age <= 35:
    print("The age is right")
    if have_id == True:
        print("You have a valid license")
        if salary >= 35000:
            print("Perfect you are eligible!")
        else:
            print("I am sorry, but you are below our minimum requirements.")
    else:
        print("Sorry but you need to have a valid license.")
else:
    print("You are above the age limit!")
Every time i execute the program, i am able to input the information, however for the result for some reason the program is skipping the if salary >= 35000: line and also for have_id printing out the else statement, regardless of the validity of any of the information. Below are two examples.

1st example with all valid answers, which should print out the following:
The age is right
You have a valid license
Perfect you are elegible

However this is what prints out:


C:\Users\rajib\PycharmProjects\Helloworld\venv\Scripts\python.exe C:/Users/rajib/PycharmProjects/Helloworld/app.py
Welcome to our online elegibility checker!
Please enter your age:29
Do you have valid id: [Y/N]:y
What is your annual salary:$40000
The age is right
Sorry but you need to have a valid license.

Process finished with exit code 0

[b]2nd scenario:
age and license is valid but not salary[:
This is what prints out:/b]

C:\Users\rajib\PycharmProjects\Helloworld\venv\Scripts\python.exe C:/Users/rajib/PycharmProjects/Helloworld/app.py
Welcome to our online elegibility checker!
Please enter your age:29
Do you have valid id: [Y/N]:y
What is your annual salary:$400
The age is right
Sorry but you need to have a valid license.

Process finished with exit code 0

Again as i said, i am very new to programming and i am following a book, however the book is not that detailed, and i have put the code in as exactly as the book has. So please, can you help me understand what my mistake is.
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,628 Nov-05-2022, 11:33 AM
Last Post: Mavoz
  Whats wrong with the elif? inunanimous93 3 2,505 Nov-30-2020, 03:58 AM
Last Post: deanhystad
  Can u see this code and tell whats wrong with it? AhmadKamal 14 5,421 Apr-29-2020, 11:09 AM
Last Post: jefsummers
  python gives wrong string length and wrong character thienson30 2 3,044 Oct-15-2019, 08:54 PM
Last Post: Gribouillis
  Whats a good design/approach? hshivaraj 1 1,796 Sep-16-2019, 01:44 AM
Last Post: snippsat
  elevator simulator...whats the wrong at this code? tasos710 5 5,947 Jun-11-2019, 01:38 AM
Last Post: micseydel
  whats the difference between sys.exit() and break? mitmit293 1 4,133 Jan-27-2019, 09:46 PM
Last Post: ichabod801
  Whats wrong with this code? student1 1 2,430 May-18-2018, 04:19 PM
Last Post: skorpius_
  I have no clue whats wrong... Jack_03 1 2,850 Sep-28-2017, 05:36 PM
Last Post: nilamo
  Whats wrong with line 12? brimalm 2 3,219 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