Program for Fibonacci Series
Program for Fibonacci Series
def fibonacci(n):
series.append(a) # Step 4: Add the current number 'a' to the series list
a, b = b, a + b # Step 5: Update 'a' to be 'b' and 'b' to be 'a + b' (next Fibonacci numbers)
Initially: a = 0, b = 1, series = []
Iteration 10: Append 34 → series = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]; Update → a = 55, b = 89
The function then returns the list of the first 10 Fibonacci numbers:
OUTPUT
🟢 1. Print a Message
python
CopyEdit
print("Welcome to Python!")
🟢 5. Square of a Number
python
CopyEdit
num = int(input("Enter a number: "))
print("Square is:", num * num)
🟢 7. Print Numbers 1 to 5
python
CopyEdit
for i in range(1, 6):
print(i
🔢 5. Factorial of a Number
python
CopyEdit
num = int(input("Enter a number: "))
fact = 1
for i in range(1, num + 1):
fact *= i
print("Factorial:", fact)
if num > 0:
print("Positive")
elif num < 0:
print("Negative")
else:
print("Zero")
if a > b:
print("The larger number is", a)
elif b > a:
print("The larger number is", b)
else:
print("Both numbers are equal")
if num % 2 == 0:
print("Even")
else:
print("Odd")