Python Lab Questions
Python Lab Questions
gle/85ut2raqNhs6PPV39
save your file in pdf format and upload in the above link
bit.ly/pythonqp
uploaded questions on 16.10.24(4:30pm)
1. A flight ticket pricing system applies discounts based on the age of the traveler and class
of service (Economy, Business, or First Class). The rules are:
· For Economy Class:
o Children (age < 12) get a 30% discount.
o Seniors (age 65) get a 20% discount.
o Other travelers pay the full price.
· For Business Class:
o Children get a 40% discount.
o Seniors get a 25% discount.
o Other travelers pay the full price.
· For First Class:
o Children get a 50% discount.
o Seniors get a 30% discount.
o Other travelers pay the full price.
Write a program that calculates the final ticket price based on age, class of service, and base
ticket price.
Input:
● Age: 70
● Class: "Business"
● Base ticket price: $500
Expected Output:
● "Your final ticket price is $375."
4. A complex event system accepts registrations based on the participant’s age, event type,
and membership status:
● If the event is "Concert" and the participant is under 18, they cannot register unless
they are accompanied by an adult.
● If the event is "Workshop", only people above the age of 21 can register.
● If the event is "Conference", the participant must be a member to register.
● For all other events, anyone can register.
Write a function that determines if the user can register and the type of ticket they are
eligible for (e.g., "Regular" or "VIP").
Input:
● Age: 25
● Event type: "Conference"
● Membership status: "No"
Expected Output:
● "You cannot register. You must be a member to attend this Conference."
5. An organization allows employees to take leave based on their years of service and the
type of leave they wish to apply for (sick, vacation, or personal). The leave policies are as
follows:
● Employees with less than 1 year of service are only allowed 5 sick days per year.
● Employees with 1-3 years of service are allowed 5 sick days and 5 vacation days per
year.
● Employees with 3-5 years of service are allowed 10 sick days, 10 vacation days, and
5 personal days per year.
● Employees with 5+ years of service can take unlimited sick days, 15 vacation days,
and 10 personal days per year.
Given the employee's years of service and leave type, determine if the employee has enough
leave balance to apply for the leave and calculate how many days are left after applying for
the leave.
Input:
● Employee years of service: 4
● Leave type: "vacation"
● Leave requested: 7
Expected Output:
● "You have enough vacation leave. You have 3 vacation days left."
6. A bank is assessing whether to approve a loan application based on the applicant's credit
score, annual income, and existing debt. The rules for loan approval are:
● If the credit score is below 600, the loan is automatically rejected.
● If the credit score is between 600 and 700, the bank will approve the loan only if the
annual income is greater than $50,000 and existing debt is less than $30,000.
● If the credit score is between 700 and 800, the loan will be approved if the annual
income is greater than $40,000 and existing debt is less than $40,000.
● If the credit score is above 800, the loan will be approved regardless of income or
debt.
Write a function that determines if the loan will be approved based on these conditions.
Input:
● Credit score: 650
● Annual income: $45,000
● Existing debt: $25,000
Expected Output:
● "Loan Approved: Your credit score is eligible, and your income and debt are within
limits."
7. An online election voting system allows users to vote for a candidate based on their age
and citizenship status. The rules are:
● The voter must be at least 18 years old.
● The voter must be a citizen of the country.
● If the voter has already voted, they cannot vote again.
The system needs to check:
1. Whether the voter is eligible to vote based on their age and citizenship status.
2. Whether the voter has voted before or not (this information will be provided).
Input:
● Age: 17
● Citizenship: "Yes"
● Has voted before: "No"
Expected Output:
● "You are not eligible to vote. You must be at least 18 years old."
8. You are shopping online, and the store offers a discount based on the total purchase
amount. If your purchase is over $100, you get a 10% discount. If it’s over $50 but less than
$100, you get a 5% discount. If it's below $50, no discount is applied.
● Input: Total Purchase = $120
● Input: Total Purchase = $75
● Input: Total Purchase = $30
Expected Output:
● For input $120:
"Congratulations! You've earned a 10% discount. Your final price is $108.00."
● For input $75:
"You've earned a 5% discount. Your final price is $71.25."
● For input $30:
"No discount applied. Your final price is $30.00."
9. You are planning your outfit based on the temperature of the day.
· If the temperature is below 0°C, you should wear a heavy coat.
· If the temperature is between 0°C and 15°C, you should wear a jacket.
· If the temperature is between 16°C and 25°C, you should wear a sweater or long
sleeves.
· If the temperature is above 25°C, you should wear shorts and a t-shirt.
· Input: Temperature = -5°C
· Input: Temperature = 10°C
· Input: Temperature = 20°C
· Input: Temperature = 30°C
Expected Output:
· For input -5°C:
"Wear a heavy coat. It’s freezing outside!"
· For input 10°C:
"Wear a jacket. It's a bit chilly."
· For input 20°C:
"Wear a sweater or long sleeves. It's comfortable."
· For input 30°C:
"Wear shorts and a t-shirt. It's quite hot!"
10. A driver must make decisions based on the traffic light color:
· If the light is green, the driver can "go".
· If the light is yellow, the driver should "slow down".
· If the light is red, the driver should "stop".
· Input: Traffic Light = "green"
· Input: Traffic Light = "yellow"
· Input: Traffic Light = "red"
Expected Output:
· For input "green":
"You can go. The light is green."
· For input "yellow":
"Slow down. The light is yellow."
· For input "red":
"Stop. The light is red."
11. A user is trying to log in to their account. The system checks their username and
password:
· If the username is "admin" and the password is "12345", the login is successful.
· If the username is correct but the password is incorrect, it shows "Incorrect
password".
· If the username is incorrect, it shows "Username not found".
· Input: Username = "admin", Password = "12345"
· Input: Username = "admin", Password = "wrongpassword"
· Input: Username = "user", Password = "12345"
Expected Output:
· For input "admin", "12345":
"Login successful. Welcome!"
· For input "admin", "wrongpassword":
"Incorrect password."
· For input "user", "12345":
"Username not found."
12. A concert's ticket price changes based on demand and seat location. The price is
calculated as follows:
● If the demand is high (more than 80% of tickets sold), the ticket price increases by
20%.
● If the demand is medium (between 40% and 80%), the price remains the same.
● If the demand is low (less than 40%), the ticket price decreases by 10%.
Additionally:
● VIP seats have a $50 premium added to the base price.
● Regular seats have no premium.
Write a function to calculate the final ticket price based on demand, seat type, and base
ticket price.
Input:
● Base ticket price: $100
● Demand: 75% (Medium)
● Seat type: "VIP"
Expected Output:
● "Your final ticket price is $150. VIP seats have an additional premium.
13. A student loan repayment system calculates the amount that a borrower should pay per
month based on their income and the loan amount. The rules are as follows:
● If the borrower’s annual income is less than $40,000, the monthly repayment is 10%
of the loan amount.
● If the annual income is between $40,000 and $80,000, the monthly repayment is 8%
of the loan amount.
● If the annual income is above $80,000, the monthly repayment is 5% of the loan
amount.
● However, if the borrower is under 25 years old, they get a 5% discount on their
monthly repayment, regardless of their income.
Write a function to calculate the monthly repayment based on the borrower’s age, annual
income, and loan amount.
Input:
● Age: 24
● Annual income: $70,000
● Loan amount: $20,000
Expected Output:
● "Your monthly repayment is $120.00 after the discount."
16. A company has an attendance bonus system. Employees can receive bonuses based on:
● Employees who attend work for all 30 days of the month receive a $200 bonus.
● Employees who miss 1 to 3 days receive a $100 bonus.
● Employees who miss more than 3 days receive no bonus.
● If the employee is on sick leave for more than 2 days, the bonus is halved.
Write a function that calculates the attendance bonus based on the days missed and the
number of sick days.
Input:
● Days missed: 3
● Sick days: 1
Expected Output:
● "Your attendance bonus is $100."
—--ending—-
=============
1. Write a program to display the last digit of a number.
2. Write a program to display “hello” if a number entered by a user is a multiple
of five otherwise print “Bye”
3. Write a program to check whether the last digit of a number is divisible by 3 or
not
4. Number divisible by 3 and ending number is 3
5. Write a program to calculate the electricity bill (accept number of unit from
user) according to the following criteria :
Unit Price
First 100 units no charge
Next 100 units Rs 5 per unit
After 200 units Rs 10 per unit
(For example if input unit is 350 than total bill amount is Rs2000)
0+500+1500=2000
6. Write a program to accept the cost price of a bike and display the road tax to be
paid according to the following criteria :
7. Write a program to accept a number from 1 to 7 and display the name of the
day like 1 for Sunday , 2 for Monday and so on.
x = ["apple", "banana"]
print("banana" in x)
9. Accept any city from the user and display monument of that city.
City Monument
Delhi Red Fort
Agra Taj Mahal
Jaipur Jal Mahal
10. Write a program to whether a number (accepted from user) is divisible by 2 and
3 both.
12. Accept the marked price from the user and calculate the Net amount
as(Marked Price – Discount) to pay according to following criteria:
Marked Price Discount
>10000 20%
13. Accept three sides of a triangle and check whether it is an equilateral, isosceles
or scalene triangle.
Note :
An equilateral triangle is a triangle in which all three sides are equal.
A scalene triangle is a triangle that has three unequal sides.
An isosceles triangle is a triangle with (at least) two equal sides.
14. Accept the age, sex (‘M’, ‘F’), number of days and display the wages
accordingly
Age Sex Wage/day
F 750
F 850
15. Accept the number of days from the user and calculate the charge for library
according to following :
Till five days : Rs 2/day.
Six to ten days : Rs 3/day.
11 to 15 days : Rs 4/day
After 15 days : Rs 5/day
16. Accept the marks of English, Math and Science, Social Studies Subject and
display the stream allotted according to following
All Subjects more than 80 marks — Science Stream
English >80 and Math, Science above 50 –Commerce Stream
English > 80 and Social studies > 80 — Humanities
=================
Branching
bit.ly/pythonqp
[1] Write a Python program that simulates a bank account withdrawal. If the
withdrawal amount exceeds the balance, print "Insufficient funds". Otherwise, deduct
the amount and print the remaining balance.(Ex: balance =50000 1.
withdrawal:20000 (print the remaining amt) 2. withdrawal is 70000 (print
insufficient funds)
[2] Write a Python program that calculates the price of a gym membership. If the user
is a student or signs up for more than 12 months, apply a 15% discount. Otherwise, no
discount is applied.(Membershipamt=12000)
[3] Write a Python program that suggests a mobile data plan based on usage. If usage
is below 5GB, suggest the "Basic" plan, if between 5GB and 20GB, suggest the
"Standard" plan, and if above 20GB, suggest the "Premium" plan.
[4] Write a Python program that calculates income tax. The tax rate is 10% for
income up to $50,000, 20% for income between $50,001 and $100,000, and 30% for
income over $100,000.
[5] Write a Python program that calculates car insurance premiums. If the driver is
under 25 years old, add a $200 surcharge. If the driver has more than 2 accidents on
record, add another $300 surcharge.
[6] Write a Python program that calculates health insurance premiums. If the person
is under 40, the premium is $300. If they are over 40 and diabetes, the premium is
$500. If they are over 40 and do not have diabetes, the premium is $400.
[7] Write a Python program for an online shopping cart that calculates the total bill
and applies discounts. If the user is a loyalty member, apply a 10% discount. If the
total purchase is above $200, apply an additional 5% discount. If the user is a member
and their total exceeds $300, grant them 20 loyalty points. Calculate the total payable
and loyalty points awarded
[8] Write a Python program to simulate a grocery store self-checkout system. The
program should allow the user to input the prices of 5 items. If the total price exceeds
$100, apply a 10% discount. If the user has a coupon, apply an additional 5%
discount. Calculate and display the total bill and the final amount the user has to pay
after applying discounts.
[9] Write a Python program that calculates the total cost of renting a car. The base
price is $40 per day. Ask the user if they want insurance: basic insurance is $15 per
day, and full coverage is $30 per day. If they drive more than 100 miles per day,
charge an additional $0.10 per mile for each mile over 100. Calculate the total cost
based on the number of days, insurance plan, and mileage.
[10]Write a Python program that calculates the cost of an airline ticket. The user can
choose between Economy ($300), Business ($600), and First Class ($1000). Ask if
they want to add checked baggage ($50 per bag) and in-flight meals ($25). If the total
ticket cost exceeds $700, give them a free checked bag. Calculate and display the final
ticket price with all selected options.
[11]Write a Python program that calculates the total cost for a food delivery order.
The base delivery fee is $5. If the order is placed during peak hours (between 6 PM
and 9 PM), apply a surge charge of 25%. Ask if the user has a discount code for 10%
off. Calculate and display the total delivery cost based on the order time and discount.
3. Write a Python program that checks if a given number is positive, negative, or zero,
using nested if statements.
4. Write a Python program that takes three numbers as input and prints the largest of the
three.
5. Write a Python program that checks if a given year is a century year (divisible by 100
but not divisible by 400).
6. Write a Python program that checks the strength of a password. The password must
have at least 8 characters, including at least one uppercase letter, one lowercase letter,
one digit, and one special character.
8. Write a program to check whether a person is eligible for voting or not.(voting age
>=18)
9. Write a program to check whether a number entered is three digit number or not.
10. Write a program to find the lowest number out of two numbers excepted from user.
11. Accept the following from the user and calculate the percentage of class
attended:
a. Total number of working days
b. Total number of days for absent
After calculating percentage show that, If the percentage is less than 75, than
student will not be able to sit in exam.
12. Accept the percentage from the user and display the grade according to the following
criteria:
· Below 25 —- D
· 25 to 45 —- C
· 45 to 50 —- B
· 50 to 60 –– B+
· 60 to 80 — A
· Above 80 –- A+
=========
Looping
print(i, end=='?')
i=2 i=100 c = -9
for x in range(i): while i<57: while c < 20:
x+=1 print(i) c += 3
print(x) i+=5 print(c)
print("x")
How many times the for x in range(10,20):
following loop execute? if (x%2==0):
continue
c=0 print(x)
while c < 20:
c += 2
Write a program to display sum of odd numbers and even numbers that
fall between 12 and 37(including both numbers)
Write a program to display all the numbers which are divisible by 11 but
not by 2 between 100 and 500.
Write a program to display product of the digits of a number accepted from the
user. Ex: 123 output: 6
Write a program to find the sum of the digits of a number accepted from user
Convert the following loop into for loop :
x=4
while(x<=8):
print(x*10)
x+=2
Write a program to print all prime numbers that fall between two
numbers including both(accept two numbers from the user)
Write a program that keep on accepting number from the user until user
enters Zero. Display the sum and average of all the numbers.
Pattern Problem
1 **** 55555
12 *** 4444
123 ** 333
1234 * 22
1
A 1 2 3 4 A A A A
BC 1 2 3 A A A A
DEF 1 2 A A A A
GHIJ 1 A A A A
KLMNO