0% found this document useful (0 votes)
12 views6 pages

Python Lab P2.1

Uploaded by

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

Python Lab P2.1

Uploaded by

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

Python Lab 2

SAPID : 60005240023
Name : Jackin Joshi
Date : 12 August 20
Class and Batch : M1-2

Program 3: Write a program that will ask a user for weight in kg and height in m. The
program should calculate BMI using the formula weight/(height * height), print the BMI and
classify accordingly.
Underweight < 18.5
Normal range 18.5 - 25 (excluding 25)
Overweight 25 - 30 (excluding 30)
Obese >=30

Program:
weight = float(input("Enter your weight in kg: "))
height = float(input("Enter your height in meters: "))
bmi = weight / (height * height)
print(f"Your BMI is: {bmi:.2f}")
if bmi < 18.5:
print("Category: Underweight")
elif 18.5 <= bmi < 25:
print("Category: Normal range")
elif 25 <= bmi < 30:
print("Category: Overweight")
else:
print("Category: Obese")
Output: (Attach a screen shot)
Enter your weight in kg: 68
Enter your height in meters: 1.75
Your BMI is: 22.20
Category: Normal range
Python Lab 2

Program 4: Write a program to print the multiplication table of 7


Program:
# Program 4: Multiplication table of 7
for i in range(1, 11):
print(f"7 x {i} = {7 * i}")

Output: (Attach a screen shot)


7x1=7
7 x 2 = 14
7 x 3 = 21
7 x 4 = 28
7 x 5 = 35
7 x 6 = 42
7 x 7 = 49
7 x 8 = 56
7 x 9 = 63
7 x 10 = 70
Python Lab 2

Program 5: Write a program to calculate the sum of first n integers. The program should ask
the user a enter an integer say n. The computer should calculate the sum of integers from 1 to
n and display the result. For e.g., if a user enters 5, the computer should enter the value for 1
+ 2 + 3 + 4 + 5 i.e., 15

Program:
n = int(input("Enter an integer n: "))
total_sum = n * (n + 1) // 2
print(f"The sum of first {n} integers is: {total_sum}")

Output: (Attach a screen shot)


Enter an integer n: 5
The sum of first 5 integers is: 15
Python Lab 2

Program 6: Given an integer number n, you have to print the factorial of this number.

Program:
n = int(input("Enter a number: "))
factorial = 1
for i in range(1, n + 1):
factorial *= i
print(f"The factorial of {n} is: {factorial}")

Output: (Attach a screen shot)


Enter a number: 5
The factorial of 5 is: 120
Python Lab 2

Program 7: Write a program that manages visitors at a police station. The visitors need to
collect token numbers and wait at the reception till their number is called. A monitor set up at
the waiting area should display the token number that can go in. In case of an emergency
situation, the inspector cancels remaining numbers for the day and leaves the station.

Program:
tokens = []
current_token = 1
while True:
print("\n1. Get a token")
print("2. Call next token")
print("3. Emergency: Cancel all remaining tokens")
print("4. Exit")
choice = input("Enter your choice: ")
if choice == "1":
[Link](current_token)
print(f"Token {current_token} issued.")
current_token += 1
elif choice == "2":
if tokens:
print(f"Token {[Link](0)}, please proceed.")
else:
print("No tokens to call.")
elif choice == "3":
[Link]()
print("All remaining tokens cancelled due to emergency.")
elif choice == "4":
print("Exiting system.")
break
else:
print("Invalid choice. Try again."
Output: (Attach a screen shot)

1. Get a token
2. Call next token
Python Lab 2

3. Emergency: Cancel all remaining tokens


4. Exit
Enter your choice: 1
Token 1 issued.

Enter your choice: 1


Token 2 issued.

Enter your choice: 2


Token 1, please proceed.

Enter your choice: 3


All remaining tokens cancelled due to emergency.

Enter your choice: 4


Exiting system.

You might also like