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

50 Beginner Python Programs

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 views4 pages

50 Beginner Python Programs

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

50 Simple Python Programs for Beginners

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

2. Add Two Numbers


a=5 b=3 print(a+b)

3. Subtract Two Numbers


a=10 b=4 print(a-b)

4. Multiply Two Numbers


a=6 b=7 print(a*b)

5. Divide Two Numbers


a=20 b=5 print(a/b)

6. Find Remainder
print(10 % 3)

7. Swap Two Variables


a,b=5,10 a,b=b,a print(a,b)

8. Check Even or Odd


n=7 print('Even' if n%2==0 else 'Odd')

9. Find Largest Number


a,b=8,12 print(max(a,b))

10. Find Smallest Number


a,b=8,12 print(min(a,b))

11. Square of Number


n=5 print(n*n)

12. Cube of Number


n=4 print(n**3)

13. Calculate Area of Rectangle


l,w=5,3 print(l*w)

14. Calculate Area of Circle


import math r=3 print([Link]*r*r)

15. Convert Celsius to Fahrenheit


c=25 print((c*9/5)+32)

16. Print Numbers 1 to 10


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

17. Sum of First 10 Numbers


print(sum(range(1,11)))

18. Multiplication Table


n=5 for i in range(1,11): print(n*i)

19. Factorial
n=5 f=1 for i in range(1,n+1): f*=i print(f)

20. Check Prime


n=11 print(all(n%i for i in range(2,n)))

21. Fibonacci Series


a,b=0,1 for _ in range(10): print(a); a,b=b,a+b

22. Reverse String


s='python' print(s[::-1])

23. Count Characters


s='hello' print(len(s))

24. Check Palindrome


s='madam' print(s==s[::-1])

25. Count Vowels


s='education' print(sum(c in 'aeiou' for c in s))

26. Find Maximum in List


nums=[1,5,2,9] print(max(nums))

27. Find Minimum in List


nums=[1,5,2,9] print(min(nums))

28. Sum of List


nums=[1,2,3] print(sum(nums))
29. Average of List
nums=[1,2,3] print(sum(nums)/len(nums))

30. Sort List


nums=[4,2,8,1] print(sorted(nums))

31. Remove Duplicates


nums=[1,1,2,3,3] print(list(set(nums)))

32. Count Words


s='I love Python' print(len([Link]()))

33. Check Leap Year


year=2024 print(year%4==0 and (year%100!=0 or year%400==0))

34. Simple Calculator


a,b=10,5 print(a+b,a-b,a*b,a/b)

35. Print Star Pattern


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

36. Generate Random Number


import random print([Link](1,100))

37. Roll Dice


import random print([Link](1,6))

38. Find String Length


s='Python' print(len(s))

39. Convert String to Uppercase


print('python'.upper())

40. Convert String to Lowercase


print('PYTHON'.lower())

41. Replace Word


print('I like Java'.replace('Java','Python'))

42. Check List Empty


lst=[] print(len(lst)==0)

43. Merge Lists


a=[1,2] b=[3,4] print(a+b)
44. Tuple Example
t=(1,2,3) print(t[0])

45. Dictionary Example


d={'name':'Ali'} print(d['name'])

46. Set Example


s={1,2,3} print(s)

47. Count Down


for i in range(5,0,-1): print(i)

48. Find ASCII Value


print(ord('A'))

49. Simple Function


def greet(): print('Hello') greet()

50. Lambda Function


square=lambda x:x*x print(square(5))

You might also like