0% found this document useful (0 votes)
32 views26 pages

25 Simple Python Programs for Beginners

The document contains 25 simple Python programs designed for school-level students. Each program addresses a specific task, such as finding sums, checking even/odd numbers, and calculating factorials. The document includes both the code and expected output for each program.

Uploaded by

syashvardhan329
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)
32 views26 pages

25 Simple Python Programs for Beginners

The document contains 25 simple Python programs designed for school-level students. Each program addresses a specific task, such as finding sums, checking even/odd numbers, and calculating factorials. The document includes both the code and expected output for each program.

Uploaded by

syashvardhan329
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

1.

Write a program to find the


sum of two numbers.

Code:
a=5
b=7
sum = a + b
print('Sum:', sum)

Output:
Sum: 12
2. Write a program to check if a
number is even or odd.

Code:
num = 8
if num % 2 == 0:
print('Even')
else:
print('Odd')

Output:
Even
3. Write a program to find the
largest of three numbers.

Code:
a, b, c = 10, 20, 15
if a > b and a > c:
print(a)
elif b > c:
print(b)
else:
print(c)
4. Write a program to check if a
number is positive, negative or
zero.
Code:
num = -3
if num > 0:
print('Positive')
elif num == 0:
print('Zero')
else:
print('Negative')
5. Write a program to find
factorial of a number.

Code:
n=5
fact = 1
for i in range(1, n+1):
fact *= i
print('Factorial:', fact)

Output:
Factorial: 120
6. Write a program to check if a
string is palindrome.

Code:
s = 'madam'
if s == s[::-1]:
print('Palindrome')
else:
print('Not Palindrome')

Output:
Palindrome
7. Write a program to print
Fibonacci series up to 10 terms.

Code:
a, b = 0, 1
for i in range(10):
print(a)
a, b = b, a + b

Output:
0 112 3 5 8 13 2134
8. Write a program to reverse a
number.

Code:
num = 1234
rev = 0
while num > 0:
rev = rev*10 + num%10
num //= 10
print('Reversed:', rev)

Output:
9. Write a program to print
multiplication table of 5.

Code:
for i in range(1, 11):
print('5 x', i, '=', 5*i)

Output:
5 x 1= 5 ... 5 x 10 = 50
10. Write a program to count
vowels in a string.

Code:
s = 'education'
count = 0
for ch in s:
if ch in 'aeiou':
count += 1
print('Vowels:', count)

Output:
11. Write a program to check if
a number is prime.

Code:
n=7
for i in range(2, n):
if n % i == 0:
print('Not Prime')
break
else:
print('Prime')
12. Write a program to find sum
of digits of a number.

Code:
n = 123
s= 0
while n > 0:
s += n % 10
n //= 10
print('Sum:', s)

Output:
13. Write a program to check if
a year is leap year.

Code:
year = 2020
if (year % 4 == 0 and year % 100 != 0) or
(year % 400 == 0):
print('Leap Year')
else:
print('Not Leap Year')

Output:
14. Write a program to print all
even numbers from 1to 20.

Code:
for i in range(2, 21, 2):
print(i)

Output:
2 4 6 8 10 12 14 16 18 20
15. Write a program to find
smallest element in a list.

Code:
lst = [3, 5, 2, 9, 1]
print('Smallest:', min(lst))

Output:
Smallest: 1
16. Write a program to swap
two numbers without using a
third variable.
Code:
a, b = 5, 10
a, b = b, a
print(a, b)

Output:
10 5
17. Write a program to find
square of a number.

Code:
n=6
print('Square:', n**2)

Output:
Square: 36
18. Write a program to print
natural numbers up to 10.

Code:
for i in range(1, 11):
print(i)

Output:
12 3 4 5 6 7 8 9 10
19. Write a program to calculate
simple interest.

Code:
p, r, t = 1000, 5, 2
si = (p*r*t)/100
print('Simple Interest:', si)

Output:
Simple Interest: 100.0
20. Write a program to print the
area of a circle.

Code:
r=7
area = 3.14 * r * r
print('Area:', area)

Output:
Area: 153.86
21. Write a program to print the
square root of a number.

Code:
import math
n = 25
print('Square Root:', [Link](n))

Output:
Square Root: 5.0
22. Write a program to find
largest element in a list.

Code:
lst = [4, 9, 1, 7]
print('Largest:', max(lst))

Output:
Largest: 9
23. Write a program to check if
a character is a vowel or
consonant.
Code:
ch = 'e'
if ch in 'aeiou':
print('Vowel')
else:
print('Consonant')

Output:
Vowel
24. Write a program to print
numbers divisible by 3 between
1and 30.
Code:
for i in range(1, 31):
if i % 3 == 0:
print(i)

Output:
3 6 9 12 15 18 2124 27 30
25. Write a program to count
even and odd numbers in a list.

Code:
lst = [1,2,3,4,5,6]
even = odd = 0
for i in lst:
if i % 2 == 0:
even += 1
else:
odd += 1
print('Even:', even)
Python Projects - Class 10
25 Simple School-Level Programs
Created by ChatGPT

You might also like