May-13-2020, 07:43 PM
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.
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.
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.