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

Shared Textoj

The document contains examples of Python code using conditional statements like if-else to solve problems like determining if a number is positive/negative/zero, finding the largest of three numbers, checking if a year is a leap year, grading a student based on score, and other scenarios. The code snippets demonstrate using conditional logic to achieve different outcomes based on specified conditions.

Uploaded by

Md Mustafa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

Shared Textoj

The document contains examples of Python code using conditional statements like if-else to solve problems like determining if a number is positive/negative/zero, finding the largest of three numbers, checking if a year is a leap year, grading a student based on score, and other scenarios. The code snippets demonstrate using conditional logic to achieve different outcomes based on specified conditions.

Uploaded by

Md Mustafa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

Question 1

Problem: Check if a number is positive, negative, or zero.

Code:

python
Copy code
number = int(input("Enter a number: "))

if number > 0:
print("The number is positive.")
elif number < 0:
print("The number is negative.")
else:
print("The number is zero.")
Question 2
Problem: Determine the largest of three numbers.

Code:

python
Copy code
a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))
c = int(input("Enter the third number: "))

if a > b and a > c:


print("The largest number is", a)
elif b > a and b > c:
print("The largest number is", b)
else:
print("The largest number is", c)
Question 3
Problem: Check if a year is a leap year.

Code:

python
Copy code
year = int(input("Enter a year: "))

if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):


print(year, "is a leap year.")
else:
print(year, "is not a leap year.")
Question 4
Problem: Grade a student based on their score.

Code:

python
Copy code
score = float(input("Enter the score: "))

if score >= 90:


print("Grade: A")
elif score >= 80:
print("Grade: B")
elif score >= 70:
print("Grade: C")
elif score >= 60:
print("Grade: D")
else:
print("Grade: F")
Question 5
Problem: Check if a character is a vowel or consonant.

Code:

python
Copy code
char = input("Enter a character: ").lower()

if char in 'aeiou':
print(char, "is a vowel.")
else:
print(char, "is a consonant.")
Question 6
Problem: Determine if a number is even or odd.

Code:

python
Copy code
number = int(input("Enter a number: "))

if number % 2 == 0:
print(number, "is even.")
else:
print(number, "is odd.")
Question 7
Problem: Determine if a person is a child, teenager, adult, or senior based on age.

Code:

python
Copy code
age = int(input("Enter age: "))

if age < 13:


print("You are a child.")
elif age < 20:
print("You are a teenager.")
elif age < 65:
print("You are an adult.")
else:
print("You are a senior.")
Question 8
Problem: Calculate the fare based on the distance traveled.

Code:

python
Copy code
distance = float(input("Enter distance traveled (in km): "))

if distance <= 5:
fare = 5
elif distance <= 15:
fare = 10
else:
fare = 20

print("The fare is $", fare)


Question 9
Problem: Determine if a person is eligible to vote based on age and citizenship.

Code:

python
Copy code
age = int(input("Enter age: "))
citizenship = input("Are you a citizen (yes/no)? ").lower()

if age >= 18 and citizenship == "yes":


print("You are eligible to vote.")
else:
print("You are not eligible to vote.")
Question 10
Problem: Check if a number is within a specified range.

Code:

python
Copy code
number = int(input("Enter a number: "))

if 1 <= number <= 100:


print("The number is within the range of 1 to 100.")
else:
print("The number is outside the range of 1 to 100.")
These questions cover a variety of conditions and scenarios to help practice the
use of if-elif-else statements in Python.

Question 22
Problem: Determine if a number is a perfect square.

Code:

python
Copy code
import math

number = int(input("Enter a number: "))

if math.isqrt(number) ** 2 == number:
print(number, "is a perfect square.")
else:
print(number, "is not a perfect square.")
Question 23
Problem: Determine if a person is eligible for a senior citizen discount.

Code:

python
Copy code
age = int(input("Enter age: "))

if age >= 65:


print("Eligible for senior citizen discount.")
else:
print("Not eligible for senior citizen discount.")
Question 24
Problem: Check if a number is within a specified range (inclusive).

Code:

python
Copy code
number = int(input("Enter a number: "))
low = int(input("Enter the lower bound: "))
high = int(input("Enter the upper bound: "))

if low <= number <= high:


print(f"{number} is within the range {low} to {high}.")
else:
print(f"{number} is not within the range {low} to {high}.")
Question 25
Problem: Determine the grade based on a percentage score.

Code:

python
Copy code
score = float(input("Enter the percentage score: "))

if score >= 90:


print("Grade: A")
elif score >= 80:
print("Grade: B")
elif score >= 70:
print("Grade: C")
elif score >= 60:
print("Grade: D")
else:
print("Grade: F")
Question 26

You might also like