0% found this document useful (0 votes)
17 views5 pages

Ai Practical File

Uploaded by

Gunjan Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views5 pages

Ai Practical File

Uploaded by

Gunjan Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

AI HOLIDAY HOMEWORK

Q: WRITE A PROGRAM TO-


1. Print "Hello World":

Output:

Hello World

2. Add 5 and 9 and display the result:


a=5
b=9
c=a+b
print(c)
Output:
14

3. Calculate total amount to be paid at a movie theatre if 7 tickets are bought at a


price of 520/ticket:

t=7
p= 520
total_amount = t*p
print(total_amount)
Output:
3640

4. Accept the name from the user and greet the user:

name = str(input("Enter your name: "))


print(f"Hello {name}")
Output:

Enter your name: John


Hello John

5. Accept two numbers from the user and display its sum, product, difference, and
divide:

num1 = float(input("Enter first number: "))


num2 = float(input("Enter second number: "))

sum_result = num1 + num2


product_result = num1 * num2
difference_result = num1 - num2
AI HOLIDAY HOMEWORK

division_result = num1 / num2 if num2 != 0 else


"Undefined (division by zero)"

print(f"Sum: {sum_result}")
print(f"Product: {product_result}")
print(f"Difference: {difference_result}")
print(f"Division: {division_result}")

Output:

Enter first number: 8


Enter second number: 4
Sum: 12.0
Product: 32.0
Difference: 4.0
Division: 2.0

6. Accept temperature in Celsius and convert into Fahrenheit:

celsius = float(input("Enter temperature in Celsius: "))


fahrenheit = (celsius * 9/5) + 32
print(f"Temperature in Fahrenheit: {fahrenheit}")

Output:

Enter temperature in Celsius: 25


Temperature in Fahrenheit: 77.0

7. Accept distance in km and convert into meters:

km = float(input("Enter distance in kilometers: "))


meters = km * 1000
print(f"Distance in meters: {meters}")

Output:

Enter distance in kilometers: 3.5


Distance in meters: 3500.0

8. Accept marks in five subjects and calculate the aggregate:

marks = []
for i in range(5):
mark = float(input(f"Enter marks for subject {i + 1}:
"))
marks.append(mark)
aggregate = sum(marks)
print(f"Aggregate marks: {aggregate}")

Output:
AI HOLIDAY HOMEWORK

Enter marks for subject 1: 75


Enter marks for subject 2: 80
Enter marks for subject 3: 85
Enter marks for subject 4: 90
Enter marks for subject 5: 95
Aggregate marks: 425.0

9. Swap two variables using a third variable:

a = float(input("Enter value of a: "))


b = float(input("Enter value of b: "))

# Swapping using third variable


temp = a
a = b
b = temp

print(f"After swapping, a = {a}, b = {b}")

Output:

Enter value of a: 5
Enter value of b: 10
After swapping, a = 10.0, b = 5.0

10. Calculate area and perimeter of a rectangle by accepting length and breadth
from the user:

length = float(input("Enter the length of the rectangle:


"))
breadth = float(input("Enter the breadth of the
rectangle: "))

area = length * breadth


perimeter = 2 * (length + breadth)

print(f"Area: {area}")
print(f"Perimeter: {perimeter}")

Output:

Enter the length of the rectangle: 5


Enter the breadth of the rectangle: 3
Area: 15.0
Perimeter: 16.0

11. Calculate area and circumference of a circle by accepting radius from the user:

radius = float(input("Enter the radius of the circle: "))


AI HOLIDAY HOMEWORK

area = 3.14 * radius * radius


circumference = 2 * 3.14 * radius

print(f"Area: {area}")
print(f"Circumference: {circumference}")

Output:

Enter the radius of the circle: 7


Area: 153.86
Circumference: 43.96

12. Input time in seconds and convert into minutes and hours:

seconds = int(input("Enter time in seconds: "))

minutes = seconds // 60
remaining_seconds = seconds % 60
hours = minutes // 60
remaining_minutes = minutes % 60

print(f"{hours} hours, {remaining_minutes} minutes,


{remaining_seconds} seconds")

Output:

Enter time in seconds: 3661


1 hours, 1 minutes, 1 seconds

13. Accept Basic + Allow – Deduction = Net salary and calculate net salary:

basic = float(input("Enter Basic salary: "))


allow = float(input("Enter Allowances: "))
deduction = float(input("Enter Deductions: "))

net_salary = basic + allow - deduction

print(f"Net Salary: {net_salary}")

Output:

Enter Basic salary: 50000


Enter Allowances: 10000
Enter Deductions: 5000
Net Salary: 55000.0

14. Calculate BMI after taking height and weight from the user:

weight = float(input("Enter your weight in kg: "))


height = float(input("Enter your height in meters: "))
AI HOLIDAY HOMEWORK

bmi = weight / (height ** 2)

print(f"Your BMI is: {bmi}")

Output:

Enter your weight in kg: 70


Enter your height in meters: 1.75
Your BMI is: 22.857142857142858

You might also like