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

40 Python Programs

The document lists 40 important Python programs designed for Class 11 exam practice, covering a variety of topics such as basic input/output, arithmetic operations, control structures, and data manipulation. Each program is presented with a brief description and the corresponding code snippet. This serves as a practical guide for students to enhance their programming skills in Python.

Uploaded by

nnz2yjnf2j
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 views6 pages

40 Python Programs

The document lists 40 important Python programs designed for Class 11 exam practice, covering a variety of topics such as basic input/output, arithmetic operations, control structures, and data manipulation. Each program is presented with a brief description and the corresponding code snippet. This serves as a practical guide for students to enhance their programming skills in Python.

Uploaded by

nnz2yjnf2j
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

40 Important Python Programs (Class 11 Exam

Practice)

1) Hello World
print("Hello, World!")

2) Add Two Numbers


a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print("Sum is:", a + b)

3) Even or Odd
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even number")
else:
print("Odd number")

4) Largest of Three Numbers


a = int(input("Enter 1st number: "))
b = int(input("Enter 2nd number: "))
c = int(input("Enter 3rd number: "))
if a >= b and a >= c:
print("Largest is", a)
elif b >= c:
print("Largest is", b)
else:
print("Largest is", c)

5) Simple Calculator
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
op = input("Enter operator (+ - * /): ")
if op == "+":
print("Result:", a + b)
elif op == "-":
print("Result:", a - b)
elif op == "*":
print("Result:", a * b)
elif op == "/":
print("Result:", a / b)
else:
print("Invalid operator")

6) Leap Year
year = int(input("Enter year: "))
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
print("Leap Year")
else:
print("Not Leap Year")

7) Positive Negative Zero


n = int(input("Enter number: "))
if n > 0:
print("Positive")
elif n < 0:
print("Negative")
else:
print("Zero")

8) Factorial
num = int(input("Enter a number: "))
fact = 1
for i in range(1, num + 1):
fact *= i
print("Factorial is:", fact)

9) Fibonacci
n = int(input("Enter number of terms: "))
a, b = 0, 1
for _ in range(n):
print(a, end=" ")
a, b = b, a + b

10) Sum of Natural Numbers


n = int(input("Enter n: "))
total = sum(range(1, n + 1))
print("Sum:", total)

11) Prime Check


num = int(input("Enter a number: "))
if num > 1:
for i in range(2, num):
if num % i == 0:
print("Not prime")
break
else:
print("Prime")
else:
print("Not prime")

12) Reverse Number


num = int(input("Enter a number: "))
rev = 0
while num > 0:
rev = rev * 10 + num % 10
num //= 10
print("Reverse:", rev)
13) Sum of Digits
num = int(input("Enter number: "))
total = 0
while num > 0:
total += num % 10
num //= 10
print("Sum of digits:", total)

14) Square and Cube


n = int(input("Enter number: "))
print("Square:", n**2)
print("Cube:", n**3)

15) BMI
weight = float(input("Weight in kg: "))
height = float(input("Height in m: "))
print("BMI:", weight/(height**2))

16) Area of Circle


r = float(input("Enter radius: "))
print("Area:", 3.14159*r*r)

17) Star Pattern


for i in range(1,6):
print("* "*i)

18) Number Pattern


for i in range(1,6):
for j in range(1,i+1):
print(j, end=" ")
print()

19) Character Type


ch = input("Enter character: ")
if [Link]():
print("Uppercase")
elif [Link]():
print("Lowercase")
elif [Link]():
print("Digit")
else:
print("Special")

20) Grade
m = float(input("Enter percentage: "))
if m>=90: print("A")
elif m>=75: print("B")
elif m>=60: print("C")
else: print("D")

21) Palindrome String


s = input("Enter string: ")
print("Palindrome" if s==s[::-1] else "Not Palindrome")

22) Count Vowels


s = input("Enter string: ")
print(sum(1 for c in [Link]() if c in "aeiou"))

23) Largest in List


arr = list(map(int,input().split()))
print(max(arr))

24) Smallest in List


arr = list(map(int,input().split()))
print(min(arr))

25) Remove Duplicates


arr = list(map(int,input().split()))
print(list(set(arr)))

26) Character Occurrence


s = input()
ch = input()
print([Link](ch))

27) Binary to Decimal


b = input()
print(int(b,2))

28) Decimal to Binary


n = int(input())
print(bin(n)[2:])

29) Celsius to Fahrenheit


c = float(input())
print((c*9/5)+32)

30) Fahrenheit to Celsius


f = float(input())
print((f-32)*5/9)

31) Multiplication Table


n = int(input())
for i in range(1,11):
print(n,"x",i,"=",n*i)

32) Sum of Even 1-50


print(sum(i for i in range(1,51) if i%2==0))

33) Armstrong
num = int(input())
print("Armstrong" if num==sum(int(d)**3 for d in str(num)) else "Not")

34) GCD
import math
a=int(input()); b=int(input())
print([Link](a,b))

35) LCM
import math
a=int(input()); b=int(input())
print(abs(a*b)//[Link](a,b))

36) Word Count


s=input()
print(len([Link]()))

37) Reverse String


s=input()
print(s[::-1])

38) Search in List


arr=list(map(int,input().split()))
x=int(input())
print("Found" if x in arr else "Not Found")
39) Area Menu
print("1 Circle 2 Rectangle")
c=int(input())
if c==1:
r=float(input())
print(3.14*r*r)
elif c==2:
l=float(input()); b=float(input())
print(l*b)

40) Matrix Input


arr=[list(map(int,input().split())) for _ in range(3)]
print(arr)

You might also like