Notification texts go here Contact Us Click here

Here A list of some basic Python programs covering different concepts:

Please wait 0 seconds...
Scroll Down and click on Go to Link for destination
Congrats! Link is Generated
  1. >> Here's a list of some basic Python programs
  2. covering different concepts:
  3.  
  4. 1. Hello, World! Program:
  5.  
  6.  
  7. print("Hello World!")
  8.  
  9. Output :
  10. Hello world!
  11.  
  12. 2. Sum of Two Numbers:
  13.  
  14.  
  15. num1 = int(input("Enter value of num1: "))
  16. num2 = int(input("Enter value of num2: "))
  17. sum_result = num1 + num2
  18. print("Sum:", sum_result)
  19.  
  20. Output :
  21. Enter value of num1: 34
  22. Enter value of num2: 56
  23. Sum: 90
  24.  
  25. 3. Finding the Largest Number in a List:
  26.  
  27. numbers = [12, 45, 89, 23, 67]
  28. max_number = max(numbers)
  29. print("Largest Number:", max_number)
  30.  
  31. Output :
  32. Largest Number: 89
  33.  
  34.  
  35. 4. Factorial of a Number:
  36.  
  37. def factorial(n):
  38. if n == 0:
  39. return 1
  40. else:
  41. return n * factorial(n-1)
  42. #user input any number
  43. num = int(input("Enter number of factorial found: "))
  44. print("Factorial of", num, "is", factorial(num))
  45.  
  46. Output :
  47. Enter number of factorial found: 5
  48. Factorial of 5 is 120
  49.  
  50. 5. Checking if a Number is Prime:
  51.  
  52.  
  53. def is_prime(n):
  54. if n < 2:
  55. return False
  56. for i in range(2, int(n**0.5) + 1):
  57. if n % i == 0:
  58. return False
  59. return True
  60.  
  61. num =int(input("Enter the number: "))
  62. if is_prime(num):
  63. print(num, "is a prime number.")
  64. else:
  65. print(num, "is not a prime number.")
  66.  
  67. Output:
  68. Enter the number: 6
  69. 6 is not a prime number.
  70. Enter the number: 27
  71. 27 is not a prime number.
  72.  
  73.  
  74.  
  75. 6. Reversing a String:
  76.  
  77. #user input the string
  78. string = input("Enter the string: ")
  79. reversed_string = string[::-1]
  80. print("Reversed String:", reversed_string)
  81.  
  82. Output :
  83. Enter the string: Hello Python
  84. Reversed String: nohtyP olleH
  85.  
  86.  
  87. 7. Counting the Occurrences of Each Character in a String:
  88.  
  89. #user enter any string from a to z
  90. string = input("Enter any string from a to z: ")
  91. char_counts = {}
  92. for char in string:
  93. char_counts[char] = char_counts.get(char, 0) + 1
  94.  
  95. print("Character Counts:", char_counts)
  96.  
  97. Output :
  98. Enter any string from a to z: jaishreeram
  99. Character Counts: {'j': 1, 'a': 2, 'i': 1, 's': 1, 'h': 1, 'r': 2, 'e': 2, 'm': 1}
  100.  
  101.  
  102. 8. Checking if a String is a Palindrome:
  103.  
  104. def is_palindrome(s):
  105. return s == s[::-1]
  106.  
  107. string = input("Enter any string : ")
  108. if is_palindrome(string):
  109. print(string, "is a palindrome.")
  110. else:
  111. print(string, "is not a palindrome.")
  112.  
  113. Output :
  114. Enter any string : aabbaa
  115. aabbaa is a palindrome.
  116.  
  117.  
  118. 9. Fibonacci Series:
  119.  
  120. def fibonacci(n):
  121. if n <= 0:
  122. return []
  123. elif n == 1:
  124. return [0]
  125. elif n == 2:
  126. return [0, 1]
  127. else:
  128. series = [0, 1]
  129. for i in range(2, n):
  130. next_num = series[-1] + series[-2]
  131. series.append(next_num)
  132. return series
  133.  
  134. n_terms = int(input("Enter the number: "))
  135. fib_series = fibonacci(n_terms)
  136. print("Fibonacci Series:", fib_series)
  137.  
  138. Output :
  139. Enter the number: 10
  140. Fibonacci Series: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
  141.  
  142.  
  143. These programs cover various concepts like printing,
  144. basic arithmetic,lists, functions, loops, conditionals,
  145. and string manipulation in Python. They should give you
  146. a good starting point to explore different aspects of Python programming.

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.