Python Project: All Types of Programs with Output
1. Hello World
print("Hello World")
Output:
Hello World
2. Input from User
name = "Somnath"
print("Hello", name)
Output:
Hello Somnath
3. Addition
a = 5
b = 10
print(a+b)
Output:
15
4. Subtraction
a = 20
b = 5
print(a-b)
Output:
15
5. Multiplication
a = 4
b = 5
print(a*b)
Output:
20
6. Division
a = 20
b = 4
print(a/b)
Output:
5.0
7. Even or Odd
n = 8
if n%2==0:
print("Even")
else:
print("Odd")
Output:
Even
8. Positive or Negative
n = -5
if n>0:
print("Positive")
else:
print("Negative")
Output:
Negative
9. Largest of 3 Numbers
a,b,c = 5,9,3
print(max(a,b,c))
Output:
9
10. Leap Year
year = 2024
if year%4==0:
print("Leap Year")
Output:
Leap Year
11. Factorial
n=5
fact=1
for i in range(1,n+1):
fact*=i
print(fact)
Output:
120
12. Prime Number
n=7
flag=True
for i in range(2,n):
if n%i==0:
flag=False
if flag:
print("Prime")
Output:
Prime
13. Palindrome
s="madam"
if s==s[::-1]:
print("Palindrome")
Output:
Palindrome
14. Reverse String
s="Python"
print(s[::-1])
Output:
nohtyP
15. Count Vowels
s="education"
count=0
for i in s:
if i in "aeiou":
count+=1
print(count)
Output:
5
16. Fibonacci Series
a,b=0,1
for i in range(5):
print(a,end=" ")
a,b=b,a+b
Output:
0 1 1 2 3
17. Swap Two Numbers
a=5
b=10
a,b=b,a
print(a,b)
Output:
10 5
18. Multiplication Table
n=2
for i in range(1,6):
print(n*i)
Output:
2
4
6
8
10
19. Sum of Digits
n=123
s=0
while n>0:
s+=n%10
n//=10
print(s)
Output:
6
20. Armstrong Number
n=153
s=0
t=n
while t>0:
d=t%10
s+=d**3
t//=10
print(s==n)
Output:
True
21. List Example
lst=[1,2,3]
print(lst)
Output:
[1, 2, 3]
22. List Sorting
lst=[4,1,3]
[Link]()
print(lst)
Output:
[1, 3, 4]
23. Tuple Example
t=(1,2,3)
print(t)
Output:
(1, 2, 3)
24. Dictionary Example
d={"a":1,"b":2}
print(d)
Output:
{'a': 1, 'b': 2}
25. Set Example
s={1,2,3}
print(s)
Output:
{1, 2, 3}
26. Function Example
def add(a,b):
return a+b
print(add(2,3))
Output:
5
27. Lambda Function
square=lambda x:x*x
print(square(4))
Output:
16
28. File Handling
f=open("[Link]","w")
[Link]("Hello")
[Link]()
print("File Written")
Output:
File Written
29. Exception Handling
try:
print(10/0)
except:
print("Error")
Output:
Error
30. Class and Object
class Student:
def show(self):
print("Student Class")
obj=Student()
[Link]()
Output:
Student Class