1.
Hello World
print("Hello, World!")
This is the simplest Python program. It prints 'Hello, World!' to the console.
2. Sum of Two Numbers
a = 5
b = 3
print("Sum:", a + b)
This program adds two numbers and prints the result.
3. Check Even or Odd
num = 7
if num % 2 == 0:
print("Even")
else:
print("Odd")
This program checks whether a number is even or odd.
4. Factorial using Recursion
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)
print(factorial(5))
This program calculates the factorial of a number using a recursive function.
5. Fibonacci Series
a, b = 0, 1
for _ in range(10):
print(a, end=" ")
a, b = b, a + b
This program prints the first 10 numbers of the Fibonacci series.