0% found this document useful (0 votes)
4 views4 pages

Practical File

The document provides three Python programs: one to check voting eligibility based on age, another to determine a student's grade based on marks, and a third to identify if a number is positive, negative, or zero. Each program includes sample runs, instructions on how to execute the code, and optional looping versions for repeated checks. The programs utilize conditional statements to provide the necessary outputs based on user input.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

Practical File

The document provides three Python programs: one to check voting eligibility based on age, another to determine a student's grade based on marks, and a third to identify if a number is positive, negative, or zero. Each program includes sample runs, instructions on how to execute the code, and optional looping versions for repeated checks. The programs utilize conditional statements to provide the necessary outputs based on user input.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Practical File

1) WAP to check if a person can vote

Code (save as vote_check.py)

# Program: Voting eligibility checker

# Step 1: Take input

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

# Step 2: Decision using conditionals

if age >= 18:

print("You are eligible to vote.")

else:

print("You are not eligible to vote yet.")

How to run

 IDLE: Open vote_check.py → press F5 (Run Module).

 VS Code/Terminal: python vote_check.py (or py vote_check.py on Windows).

Sample runs (exact console I/O)

Run 1

Enter your age: 20

You are eligible to vote.

Run 2

Enter your age: 15

You are not eligible to vote yet.

Run 3 (boundary check)

Enter your age: 18

You are eligible to vote.

(Optional) Looping version (runs repeatedly until you type N)

while True:

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

print("You are eligible to vote." if age >= 18 else "You are not eligible to vote yet.")
if input("Check another? (Y/N): ").strip().upper() == "N":

break

2) WAP to check the grade of a student

Code (save as grade_check.py)

# Program: Grade calculator based on marks

marks = float(input("Enter your marks (0-100): "))

if marks >= 90:

print("Grade: A+")

elif marks >= 80:

print("Grade: A")

elif marks >= 70:

print("Grade: B")

elif marks >= 60:

print("Grade: C")

elif marks >= 50:

print("Grade: D")

else:

print("Grade: F (Fail)")

How to run

 IDLE: Open grade_check.py → F5.

 VS Code/Terminal: python grade_check.py.

Sample runs

Run 1

Enter your marks (0-100): 85

Grade: A

Run 2

Enter your marks (0-100): 72

Grade: B

Run 3
Enter your marks (0-100): 49

Grade: F (Fail)

Run 4 (boundary checks)

Enter your marks (0-100): 90

Grade: A+

(Optional) Looping version

while True:

marks = float(input("Enter your marks (0-100): "))

if marks >= 90:

print("Grade: A+")

elif marks >= 80:

print("Grade: A")

elif marks >= 70:

print("Grade: B")

elif marks >= 60:

print("Grade: C")

elif marks >= 50:

print("Grade: D")

else:

print("Grade: F (Fail)")

if input("Another student? (Y/N): ").strip().upper() == "N":

break

3) Input a number and check if it’s positive, negative, or zero

Code (save as number_sign.py)

# Program: Number sign checker (positive/negative/zero)

num = float(input("Enter a number: "))

if num > 0:

print("The number is positive.")

elif num < 0:


print("The number is negative.")

else:

print("The number is zero.")

How to run

 IDLE: Open number_sign.py → F5.

 VS Code/Terminal: python number_sign.py.

Sample runs

Run 1

Enter a number: 10

The number is positive.

Run 2

Enter a number: -7

The number is negative.

Run 3

Enter a number: 0

The number is zero.

(Optional) Looping version

while True:

num = float(input("Enter a number: "))

if num > 0:

print("The number is positive.")

elif num < 0:

print("The number is negative.")

else:

print("The number is zero.")

if input("Check another? (Y/N): ").strip().upper() == "N":

break

You might also like