Some basic programs in Python
Problem 1: Finding the Largest of Three Numbers in Python
Problem 5: Reverse a String
a = int(input("Enter a: "))
b = int(input("Enter b: "))
c = int(input("Enter c: "))
if a >= b and a >= c:
print("a is the largest")
elif b >= a and b >= c:
print("b is the largest")
else:
print("c is the largest")
Problem 2: Find the Factorial of a Number
num = int(input("Enter a number: "))
factorial = 1
if num < 0:
print("Factorial is not defined for negative numbers.")
elif num == 0:
print("The factorial of 0 is 1")
else:
for i in range(1, num + 1):
factorial *= i
print("The factorial of", num, "is", factorial)
Problem 3: Print the Fibonacci Series
num = int(input("Enter the number of terms: "))
fibonacci = [0, 1]
while len(fibonacci) < num:
next_num = fibonacci[-1] + fibonacci[-2]
fibonacci.append(next_num)
print("The Fibonacci series is:", fibonacci)
Problem 4: Print the Prime Number Series
Problem 5: Reverse a String
string = input("Enter a string: ")
reverse_string = string[::-1]
print("The reversed string is:", reverse_string)