0% found this document useful (0 votes)
2 views3 pages

Python Progreams Class 9

The document contains a series of Python code snippets that demonstrate basic programming concepts such as checking if a number is positive or negative, even or odd, determining leap years, finding the largest among numbers, grading based on marks, checking divisibility, and identifying vowels or consonants. Each code snippet includes user input and conditional statements to produce the desired output. These examples serve as practical exercises for beginners learning Python programming.

Uploaded by

uma.bej82
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)
2 views3 pages

Python Progreams Class 9

The document contains a series of Python code snippets that demonstrate basic programming concepts such as checking if a number is positive or negative, even or odd, determining leap years, finding the largest among numbers, grading based on marks, checking divisibility, and identifying vowels or consonants. Each code snippet includes user input and conditional statements to produce the desired output. These examples serve as practical exercises for beginners learning Python programming.

Uploaded by

uma.bej82
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
You are on page 1/ 3

1.

Check if a number is positive or negative


python
CopyEdit
num = int(input("Enter a number: "))

if num >= 0:
print("Positive number")
else:
print("Negative number")

�2. Check if a number is even or odd


python
CopyEdit
num = int(input("Enter a number: "))

if num % 2 == 0:
print("Even")
else:
print("Odd")

�3. Check whether a year is a leap year


python
CopyEdit
year = int(input("Enter a year: "))

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


print("Leap year")
else:
print("Not a leap year")

�4. Find the largest among two numbers


python
CopyEdit
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))

if a > b:
print("First number is greater")
else:
print("Second number is greater")

�5. Find the largest among three numbers (nested if)


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

if a >= b:
if a >= c:
print("a is greatest")
else:
print("c is greatest")
else:
if b >= c:
print("b is greatest")
else:
print("c is greatest")

�6. Grade according to marks (if-elif-else)


python
CopyEdit
marks = int(input("Enter marks: "))

if marks >= 90:


print("Grade: A")
elif marks >= 75:
print("Grade: B")
elif marks >= 60:
print("Grade: C")
elif marks >= 40:
print("Grade: D")
else:
print("Fail")

�7. Check whether a number is divisible by 5 and 11


python
CopyEdit
num = int(input("Enter a number: "))

if num % 5 == 0 and num % 11 == 0:


print("Divisible by 5 and 11")
else:
print("Not divisible by both")

�8. Check if character is a vowel or consonant


python
CopyEdit
ch = input("Enter a character: ")

if ch.lower() in ['a', 'e', 'i', 'o', 'u']:


print("Vowel")
else:
print("Consonant")

�9. Check if a number is a multiple of 3, 5, or both


python
CopyEdit
num = int(input("Enter a number: "))

if num % 3 == 0 and num % 5 == 0:


print("Multiple of both 3 and 5")
elif num % 3 == 0:
print("Multiple of 3")
elif num % 5 == 0:
print("Multiple of 5")
else:
print("Not a multiple of 3 or 5")

You might also like