A Int (Input ('Enter First Number: ') ) B Int (Input ('Enter Second Number: ') ) If A B: Print ('Largest Is', A) Else: Print ('Largest Is', B)
A Int (Input ('Enter First Number: ') ) B Int (Input ('Enter Second Number: ') ) If A B: Print ('Largest Is', A) Else: Print ('Largest Is', B)
A Int (Input ('Enter First Number: ') ) B Int (Input ('Enter Second Number: ') ) If A B: Print ('Largest Is', A) Else: Print ('Largest Is', B)
# Program 1: Read two numbers from the user and display the largest/smallest number
Output:
Enter first number: 45
Enter second number: 23
Largest is 45
#Program 2:
# Read two numbers from the user and display the odd/even number.
# Add 1 to even and subtract 1 from odd.
def odd_even(num):
if num % 2 == 0:
print(num, 'is even.')
num += 1
else:
print(num, 'is odd.')
num -= 1
print('New number:', num)
a = int(input('Enter first number: '))
b = int(input('Enter second number: '))
odd_even(a)
odd_even(b)
Output:
Enter first number: 6
Enter second number: -8
6 is even.
New number: 7
-8 is even.
New number: -7
#Program 3:
# Find the area of a 2D shape (square, rectangle, triangle, circle)
choice = int(input('Choose the shape to find the area of:\n1. Square\n2. Rectangle\n3.
Triangle\n4. Circle\n'))
if choice == 1:
side = int(input('Enter the side:'))
print('Area of a square with side', side, 'is', side * side)
elif choice == 2:
length = int(input('Enter the length:'))
breadth = int(input('Enter the breadth:'))
print('Area of rectangle with length', length, 'and breadth', breadth, 'is', length * breadth)
elif choice == 3:
base = int(input('Enter the base:'))
height = int(input('Enter the height:'))
print('Area of triangle with base', base, 'and height', height, 'is', 0.5 * base * height)
elif choice == 4:
radius = int(input('Enter the radius:'))
print('Area of a circle with radius', radius, 'is', round(pi * radius * radius, 2))
else:
print('Invalid choice.')
Output:
Choose the shape to find the area of:
1. Square
2. Rectangle
3. Triangle
4. Circle
1
Enter the side:3
Area of a square with side 3 is 9
2
Enter the length:2
Enter the breadth:5
Area of rectangle with length 2 and breadth 5 is
10
3
Enter the base:5
Enter the height:8
Area of triangle with base 5 and height 8 is 20.0
4
Enter the radius:4
Area of a circle with radius 4 is 50.27
#Program 4:
# Read two numbers from the user and compute x power n
Output:
Enter number: 5
Enter power: 3
5 raised to 3 is 125
#Program 5:
# Program that displays first 9 terms of Fibonacci series
n1 = -1
n2 = 1
print('First 9 Fibonacci terms are:')
for i in range(1, 10):
n3 = n1 + n2
print(n3, end=' ')
n1 = n2
n2 = n3
print()
Output:
First 9 Fibonacci terms are:
0 1 1 2 3 5 8 13 21
#Program 6:
#Program to read a string and replace all the spaces with "_".
Output:
#Program 7:
#Program to read a string and check if it is a palindrome.
Output:
************