5/8/25, 11:23 AM Rough work.
ipynb - Colab
1. Basic Data Types Write a Python program to take two integer inputs from the user and print their sum, difference, product, and quotient
# Take two integer inputs from the user
num1 = int(input("Enter the first integer: "))
num2 = int(input("Enter the second integer: "))
# Perform operations
sum_result = num1 + num2
difference = num1 - num2
product = num1 * num2
# Check if the second number is not zero before division
if num2 != 0:
quotient = num1 / num2
print(f"Quotient: {quotient}")
else:
print("Quotient: Division by zero is not allowed.")
# Print results
print(f"Sum: {sum_result}")
print(f"Difference: {difference}")
print(f"Product: {product}")
Enter the first integer: 15
Enter the second integer: 25
Quotient: 0.6
Sum: 40
Difference: -10
Product: 375
2. Using if-else Write a Python program that takes an integer input from the user and checks whether it is even or odd. Print an appropriate
message
# Take an integer input from the user
num = int(input("Enter an integer: "))
# Check if the number is even or odd
if num % 2 == 0:
print(f"{num} is even.")
else:
print(f"{num} is odd.")
Enter an integer: 7
7 is odd.
3. Using for Loop Write a Python program to print the multiplication table of a given number (user input) up to 10 using a for loop.
# Take input from the user
num = int(input("Enter a number to print its multiplication table: "))
# Print multiplication table using for loop
print(f"Multiplication Table for {num}:")
for i in range(1, 11):
print(f"{num} x {i} = {num * i}")
Enter a number to print its multiplication table: 5
Multiplication Table for 5:
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50
4. Working with Lists Write a Python program to: o Create a list of five numbers entered by the user. o Remove the second element from
the list
# Create an empty list
numbers = []
[Link] 1/3
5/8/25, 11:23 AM Rough [Link] - Colab
# Take five numbers as input from the user
print("Enter five numbers:")
for i in range(5):
num = int(input(f"Enter number {i+1}: "))
[Link](num)
# Display original list
print("Original list:", numbers)
# Remove the second element (index 1)
if len(numbers) >= 2:
removed = [Link](1)
print(f"Removed second element: {removed}")
else:
print("List has less than two elements, cannot remove second element.")
# Display updated list
print("Updated list:", numbers)
Enter five numbers:
Enter number 1: 10
Enter number 2: 20
Enter number 3: 30
Enter number 4: 40
Enter number 5: 50
Original list: [10, 20, 30, 40, 50]
Removed second element: 20
Updated list: [10, 30, 40, 50]
5. Using Functions Write a Python function calculate_area(radius) that takes the radius of a circle as input and returns its area. (Use π =
3.1416)
# Define the function
def calculate_area(radius):
pi = 3.1416
area = pi * radius ** 2
return area
# Example usage
r = float(input("Enter the radius of the circle: "))
area = calculate_area(r)
print(f"The area of the circle with radius {r} is {area}")
Enter the radius of the circle: 8
The area of the circle with radius 8.0 is 201.0624
6. Using Lambda Function Write a Python program that uses a lambda function to compute the square of a given number (user input).
# Take user input
num = float(input("Enter a number to find its square: "))
# Lambda function to calculate square
square = lambda x: x ** 2
# Compute and display result
print(f"The square of {num} is {square(num)}")
Enter a number to find its square: 177
The square of 177.0 is 31329.0
Start coding or generate with AI.
[Link] 2/3
5/8/25, 11:23 AM Rough [Link] - Colab
[Link] 3/3