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

30 Essential Python Programs

The document contains 30 basic Python programs that demonstrate fundamental programming concepts. Each program includes a brief description and code snippets for tasks such as arithmetic operations, string manipulation, and control flow. These examples serve as a practical introduction to Python programming for beginners.

Uploaded by

blaze20255
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)
29 views4 pages

30 Essential Python Programs

The document contains 30 basic Python programs that demonstrate fundamental programming concepts. Each program includes a brief description and code snippets for tasks such as arithmetic operations, string manipulation, and control flow. These examples serve as a practical introduction to Python programming for beginners.

Uploaded by

blaze20255
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

30 Basic Python Programs

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

2. Add Two Numbers


a=int(input("Enter a: "))
b=int(input("Enter b: "))
print(a+b)

3. Subtract Two Numbers


a=int(input("a: "))
b=int(input("b: "))
print(a-b)

4. Multiply Two Numbers


a=int(input("a: "))
b=int(input("b: "))
print(a*b)

5. Divide Two Numbers


a=int(input("a: "))
b=int(input("b: "))
print(a/b)

6. Even or Odd
n=int(input())
print("Even" if n%2==0 else "Odd")

7. Positive or Negative
n=int(input())
print("Positive" if n>0 else "Negative" if n<0 else "Zero")

8. Largest of Two
a,b=map(int,input().split())
print(max(a,b))

9. Largest of Three
a,b,c=map(int,input().split())
print(max(a,b,c))

10. Leap Year


y=int(input())
print("Leap" if y%4==0 and y%100!=0 or y%400==0 else "Not Leap")

11. Factorial
n=int(input())
f=1
for i in range(1,n+1): f*=i
print(f)

12. Fibonacci
n=int(input())
a,b=0,1
print(a,b,end=" ")
for i in range(2,n): a,b=b,a+b; print(b,end=" ")

13. Reverse Number


n=int(input())
r=0
while n>0:
r=r*10+n%10
n//=10
print(r)

14. Palindrome Number


n=int(input())
t=n
r=0
while n>0:
r=r*10+n%10
n//=10
print("Palindrome" if t==r else "Not")

15. Armstrong Number


n=int(input())
t=n
s=0
while n>0:
d=n%10
s+=d**3
n//=10
print("Armstrong" if t==s else "Not")

16. Sum of Digits


n=int(input())
s=0
while n>0:
s+=n%10
n//=10
print(s)

17. Multiplication Table


n=int(input())
for i in range(1,11): print(n,"x",i,"=",n*i)
18. Prime Check
n=int(input())
f=True
for i in range(2,n):
if n%i==0: f=False; break
print("Prime" if f and n>1 else "Not")

19. Print 1 to N
n=int(input())
for i in range(1,n+1): print(i)

20. Sum of N Numbers


n=int(input())
print(n*(n+1)//2)

21. Count Vowels


s=input()
c=0
for ch in [Link]():
if ch in "aeiou": c+=1
print(c)

22. Reverse String


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

23. Palindrome String


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

24. String Length


s=input()
c=0
for i in s: c+=1
print(c)

25. Sum of List


lst=[1,2,3,4]
print(sum(lst))

26. Largest in List


lst=[10,20,5]
print(max(lst))

27. Count Even in List


lst=[1,2,3,4,6]
c=0
for i in lst:
if i%2==0: c+=1
print(c)

28. Calculator
a,b=map(int,input().split())
print(a+b,a-b,a*b,a/b)

29. Swap Two Numbers


a,b=map(int,input().split())
a,b=b,a
print(a,b)

30. Function Example


def add(a,b): return a+b
print(add(5,3))

You might also like