0% found this document useful (0 votes)
22 views1 page

Python Basics: Simple Programs Explained

The document provides five simple Python programs demonstrating basic programming concepts. It includes examples for printing text, summing numbers, checking even or odd values, calculating factorials using recursion, and generating the Fibonacci series. Each program is accompanied by a brief description of its functionality.

Uploaded by

fatimaansari8522
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)
22 views1 page

Python Basics: Simple Programs Explained

The document provides five simple Python programs demonstrating basic programming concepts. It includes examples for printing text, summing numbers, checking even or odd values, calculating factorials using recursion, and generating the Fibonacci series. Each program is accompanied by a brief description of its functionality.

Uploaded by

fatimaansari8522
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

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.

You might also like