Computer Science, asked by gurfatehsidhu, 7 months ago

Write a program to check whether a person can vote or not.. python

Answers

Answered by PreetiGupta2006
3

Logic:

We know that a person who is above 18 years is eligible to vote but a person who is less than 18 years is not eligible to vote.

But what if the person is exactly of 18 years?

Then we need to ask whether he/she has voter id or not .

⠀⠀⠀:So let's cöde for this python ⠀⠀⠀⠀⠀⠀⠀⠀⠀program:

for i in range(1,11):

⠀⠀print("To check whether a person is ⠀⠀⠀⠀⠀eligible to vote or not")

⠀⠀age=int(input("Enter your age"))

⠀⠀if (age>18):

⠀⠀⠀print("Congratulations, you can ⠀⠀⠀⠀⠀⠀vote")

⠀⠀elif (age==18):

⠀⠀⠀⠀print("Do you have voter id?")

⠀⠀⠀⠀ans=int(input("if yes press 1 or ⠀⠀⠀⠀⠀⠀⠀press 2 if you don't have"))

⠀⠀⠀⠀if (ans==1):

⠀⠀⠀⠀⠀⠀⠀⠀print("Congratulations, you ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀are eligible to vote ")

⠀⠀⠀⠀elif (ans==2):

⠀⠀⠀⠀⠀⠀⠀⠀print("Sorry,you are not ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀eligible to vote")

⠀⠀⠀⠀else:

⠀⠀⠀⠀⠀⠀⠀⠀print("invalid option")

⠀⠀else:

⠀⠀⠀⠀print("You are not eligible to vote ")

Note:(i) See the Output image provided ⠀⠀⠀⠀ above.

⠀⠀⠀ (ii) Make proper indentations.

Attachments:
Similar questions