### **1.
Program to Print Student Details**
# Program to display student details
name = "John Doe"
age = 14
student_class = "9th"
roll_number = 23
print("Student Details:")
print(f"Name: {name}")
print(f"Age: {age}")
print(f"Class: {student_class}")
print(f"Roll Number: {roll_number}")
#### **Output**
Student Details:
Name: John Doe
Age: 14
Class: 9th
Roll Number: 23
### **2. Program to Check if a Number is Even or Odd**
```python
number = int(input("Enter a number: "))
if number % 2 == 0:
print(f"{number} is Even")
else:
print(f"{number} is Odd")
#### **Output**
Enter a number: 5
5 is Odd
### **3. Program to Check if a Number is Even or Divisible by 5**
num = int(input("Enter a number: "))
if num % 2 == 0:
print(f"{num} is Even")
elif num % 5 == 0:
print(f"{num} is Divisible by 5")
else:
print(f"{num} is neither Even nor Divisible by 5")
#### **Output**
Enter a number: 25
25 is Divisible by 5
### **4. Program to Check if a Number is Positive, Negative, or Zero**
num = int(input("Enter a number: "))
if num > 0:
print(f"{num} is Positive")
elif num < 0:
print(f"{num} is Negative")
else:
print("The number is Zero")
#### **Output**
Enter a number: -8
-8 is Negative
### **5. Program to Find the Greater Number Between Two Numbers**
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
if a > b:
print(f"{a} is Greater")
else:
print(f"{b} is Greater")
#### **Output**
Enter first number: 7
Enter second number: 12
12 is Greater
### **6. Program to Find the Greatest Number Among Three Numbers**
a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))
c = int(input("Enter the third number: "))
if a > b and a > c:
print(f"{a} is the greatest")
elif b > c:
print(f"{b} is the greatest")
else:
print(f"{c} is the greatest")
#### **Output**
Enter the first number: 10
Enter the second number: 25
Enter the third number: 15
25 is the greatest
### **7. Program to Reverse a Given Number**
num = int(input("Enter a number: "))
reverse_num = int(str(num)[::-1])
print(f"Reversed number: {reverse_num}")
#### **Output**
Enter a number: 1234
Reversed number: 4321
### **8. Program to Find the Sum of Digits of a Number**
num = int(input("Enter a number: "))
sum_of_digits = sum(int(digit) for digit in str(num))
print(f"Sum of digits: {sum_of_digits}")
#### **Output**
Enter a number: 456
Sum of digits: 15
### **9. Program to Find the Length of a String**
text = input("Enter a string: ")
print(f"Length of the string: {len(text)}")
#### **Output**
Enter a string: Hello, World!
Length of the string: 13
### **10. Program to Create a Simple Calculator**
def calculator(a, b, operation):
if operation == '+':
return a + b
elif operation == '-':
return a - b
elif operation == '*':
return a * b
elif operation == '/':
return a / b
else:
return "Invalid operation"
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
op = input("Enter operation (+, -, *, /): ")
result = calculator(num1, num2, op)
print(f"Result: {result}")
#### **Output**
Enter first number: 10
Enter second number: 2
Enter operation (+, -, *, /): *
Result: 20.0
### **11. Program to Find Day of the Week According to Numbers (1-7)**
days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
num = int(input("Enter a number (1-7): "))
if 1 <= num <= 7:
print(f"Day of the week: {days[num - 1]}")
else:
print("Invalid input")
#### **Output**
Enter a number (1-7): 5
Day of the week: Friday
### **12. Program to Convert Temperature Between Fahrenheit and Celsius**
temp = float(input("Enter temperature: "))
unit = input("Is this Fahrenheit (F) or Celsius (C)? ").upper()
if unit == "F":
celsius = (temp - 32) * 5 / 9
print(f"{temp}°F is {celsius:.2f}°C")
elif unit == "C":
fahrenheit = (temp * 9 / 5) + 32
print(f"{temp}°C is {fahrenheit:.2f}°F")
else:
print("Invalid unit")
#### **Output**
Enter temperature: 98.6
Is this Fahrenheit (F) or Celsius (C)? F
98.6°F is 37.00°C
### **13. Program to Print Numbers from 1 to 10**
for i in range(1, 11):
print(i)
#### **Output**
8
9
10
### **14. Program to Calculate the Sum of First 10 Natural Numbers**
sum_of_numbers = sum(range(1, 11))
print(f"Sum of first 10 natural numbers: {sum_of_numbers}")
#### **Output**
Sum of first 10 natural numbers: 55
### **15. Program to Generate Multiplication Table for a Given Number**
num = int(input("Enter a number: "))
print(f"Multiplication table for {num}:")
for i in range(1, 11):
print(f"{num} x {i} = {num * i}")
#### **Output**
Enter a number: 5
Multiplication table for 5:
5x1=5
5 x 2 = 10
...
5 x 10 = 50
### **16. Program to Calculate the Factorial of a Given Number**
num = int(input("Enter a number: "))
factorial = 1
for i in range(1, num + 1):
factorial *= i
print(f"Factorial of {num} is {factorial}")
#### **Output**
Enter a number: 5
Factorial of 5 is 120
### **17. Program to Calculate Sum of All Even Numbers up to 100**
sum_of_evens = sum(i for i in range(2, 101, 2))
print(f"Sum of all even numbers up to 100: {sum_of_evens}")
#### **Output**
Sum of all even numbers up to 100: 2550
---
### **18. Program to Find Maximum and Minimum Number in a List**
numbers = [5, 12, 7, 34, 2, 89]
print(f"Maximum number: {max(numbers)}")
print(f"Minimum number: {min(numbers)}")
#### **Output**
Maximum number: 89
Minimum number: 2
### **19. Program to Swap Two Numbers**
a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))
print(f"Before swapping: a = {a}, b = {b}")
a, b = b, a
print(f"After swapping: a = {a}, b = {b}")
#### **Output**
Enter the first number: 3
Enter the second number: 7
Before swapping: a = 3, b = 7
After swapping: a = 7, b = 3
### **20. Program to Print All Prime Numbers Between 1 and 100**
print("Prime numbers between 1 and 100:")
for num in range(2, 101):
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
break
else:
print(num, end=" ")
#### **Output**
Prime numbers between 1 and 100:
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97