Class IX – Artificial Intelligence
Assignment: Introduction to Python (Program-Based)
Write each program neatly in copy and do it practically.
Use proper indentation.
Write Question first, then Program.
Q1. Write a Python program to print "Hello, World!".
Answer:
print("Hello, World!")
Q2. Write a Python program to print your name, class, and school name in separate lines.
Answer:
print("Zainab Hadis")
print("Class IX")
print("TIGPS School")
Q3. Write a Python program to display the following output:
Python is Easy
Answer:
print("Python")
print("is")
print("Easy")
Q4. Write a Python program to print numbers from 1 to 10.
Answer:
for i in range(1, 11):
print(i)
Q5. Write a Python program to store your age in a variable and print it.
Answer:
age = 14
print("Age:", age)
Q6. Write a Python program to store two integers and print their sum.
Answer:
a = 10
b = 20
print("Sum =", a + b)
Q7. Write a Python program to store a float and an integer and print them.
Answer:
x = 10.5
y=5
print("Float value:", x)
print("Integer value:", y)
Q8. Write a Python program to input the user’s name and print a welcome message.
Answer:
name = input("Enter your name: ")
print("Welcome", name)
Q9. Write a Python program to input two numbers and print their sum.
Answer:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print("Sum =", a + b)
Q10. Write a Python program to calculate the area of a rectangle.
Answer:
length = int(input("Enter length: "))
breadth = int(input("Enter breadth: "))
area = length * breadth
print("Area =", area)
Q11. Write a Python program to calculate simple interest.
Answer:
p = int(input("Enter principal: "))
r = int(input("Enter rate: "))
t = int(input("Enter time: "))
si = (p * r * t) / 100
print("Simple Interest =", si)
Q12. Write a Python program to convert Celsius to Fahrenheit.
Answer:
c = float(input("Enter temperature in Celsius: "))
f = (c * 9/5) + 32
print("Temperature in Fahrenheit =", f)
Q13. Write a Python program to swap two numbers using a temporary variable.
Answer:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
temp = a
a=b
b = temp
print("After swapping:")
print("a =", a)
print("b =", b)
Q14. Write a Python program to find the average of three numbers.
Answer:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
avg = (a + b + c) / 3
print("Average =", avg)
Q15. Write a Python program to display the square of a number.
Answer:
n = int(input("Enter a number: "))
print("Square =", n * n)
Q16. Write a Python program to calculate discounted amount.
Answer:
amount = int(input("Enter amount: "))
discount_percent = int(input("Enter discount %: "))
discount = amount * discount_percent / 100
final_amount = amount - discount
print("Discount =", discount)
print("Discounted Amount =", final_amount)
Q17. Write a Python program to calculate surface area and volume of a cuboid.
Answer:
l = int(input("Enter length: "))
b = int(input("Enter breadth: "))
h = int(input("Enter height: "))
surface_area = 2 * (l*b + b*h + l*h)
volume = l * b * h
print("Surface Area =", surface_area)
print("Volume =", volume)
Q18. Write a Python program to calculate the area of a triangle using base and height.
Answer.
base = int(input("Enter base: "))
height = int(input("Enter height: "))
area = (base * height) // 2
print("Area =", area)