Python program to check person can vote or not

Solution with out using functions
Solution using functions without passing arguments
Solution using functions and by passing arguments


Solution : Without using function
Program/Source Code

For better understanding of this example, one should have the knowledge of the following Python programming topics:

Python if…else… Statement
Python if…else…if…else… Statement
Python if…elif…if…elif…else… Statement

Python program to check person can vote or not

name=input("Enter name ");
age=int(input("Enter age "))
if(age>=18):
    print("You can vote")
else:
    print("You cannot vote")

Output:

Enter name Amit
Enter age 21
You can vote
>>>
Enter name Sumit
Enter age 12
You cannot vote
>>>



Solution : Using function Without Passing Arguments
Program/Source Code

#function definition
def vote():
    name=input("Enter name ");
    age=int(input("Enter age "))
    if(age>=18):
        print("You can vote")
    else:
        print("You cannot vote")

#function calling
vote()

Output:

Enter name Kapil
Enter age 25
You can vote
>>>
Enter name Komal
Enter age 15
You cannot vote
>>>



Solution : Using function Passing Arguments
Program/Source Code

#function definition
def vote(n,a):
    print("Name is ",n)
    if(a>=18):
        print("You can vote")
    else:
        print("You cannot vote")

#function calling
name=input("Enter name ");
age=int(input("Enter age "))
vote(name,age)

Output:

Enter name Manoj
Enter age 25
Name is Manoj
You can vote
>>>
Enter name Meena
Enter age 16
Name is Meena
You cannot vote
>>>

You May Also Like:

Python Program to check character is a vowel or not
Python Program to factorial of a number
C Language Program to Print Fibonacci Series
Python Program to Print Fibonacci Series
C Language Program for Factorial of a Number

Tutorials

Technical Questions and Important programs

Interview Questions

C Programming
C++ Programming
Basic Python Tutorial
Advanced Python Tutorial
C Language
C++ Programming
Python programming
C Important Programs
C Interview Questions
C++ Interview Questions
Python Interview Questions
HTML Interview Questions


Visitor Counter

0056756