Computer Science, asked by tanmaygkp1975, 1 month ago

1. In India a person is eligible to vote if he /she is Indian by nationality and i above or equal to 18 years. Write a program to accept name and age of person and print whether he /she is eligible to vote.​

Answers

Answered by Anonymous
253

Eligible to vote - Python

Assuming that the question needs Python program to accept name and age of person and print whether he/she is eligible to vote. As we are not given in the Question only by which programming language we write the required program, therefore here we use python program.

Before we write the required program for this question, let's first take some hint for better understanding and know that what we need to do in this program and how to write the program.

_______________...

Let us take a look at what we need to do in this program.

First we would take a user input to accept the name from the user. We know that the input() function returns a string, string is one of the basis types in Python that store text.

After that, we would take a user input to accept the age from the user and Store them as integer value. We know that when we want integer value from the user, we always use int() function to accept the integer value from the user.

After this we will check the criteria of user that user is eligible for vote or not. If the user is eligible for vote then we will display the messege.

And if the user is not eligible for vote then we will display the messege that you're not eligible.

_______________...

The Program

# Program to accept name and age of person and print whether he/she is eligible to vote

# Take input to accept name

name = input("Enter your name: ")

# Take input to accept age

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

# Check if the age greater than 18 or not

if(age >= 18):

# If the age is 18 or greater than 18 then print this

print(f"Congratulations dear {name}, you are eligible for vote.")

# Or else print this

else:

print(f"Sorry to say dear {name}, you are not eligible for vote.")

[Hashtag (#) is only a single line comment in Python, It's not printed in the program, I have used them here for understanding the program step-by-step. If you want then you can remove those comments from the program.]

_______________...

Sample run

Case 1:

Enter your name: Eldarion

Enter your age: 18

Congratulations dear Eldarion, you are eligible for vote.

Case 2:

Enter your name: Shalom

Enter your age: 15

Sorry to say dear Shalom, you are not eligible for vote.

Case 3:

Enter your name: Jack

Enter your age: 28

Congratulations dear Jack, you are eligible for vote.

_______________...

Remember: Don't forgot to give a tab after 'if' and 'else' if you are not giving a tab then it would throw a error.

Answered by lucky000001
13

age=int(input("Enter age: "))

print(["Eligible", "Not Eligible"][age<18])

When age becomes <18, condition is true. It returns 1. Element at index 1 is "Not eligible". This is printed. when condition is false, it returns 0 so eligible is pinted.

Similar questions