Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
85 views

Python Lab Questions

Uploaded by

gqtykgnfzj
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
85 views

Python Lab Questions

Uploaded by

gqtykgnfzj
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

https://forms.

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."

2. A store has a return policy with the following rules:


● If the product is returned within 30 days, the customer gets a full refund.
● If the product is returned between 31 to 60 days, the customer gets a 50% refund.
● If the product is returned between 61 to 90 days, the customer gets a 25% refund.
● If the product is returned after 90 days, no refund is given.
However, if the product is damaged or defective, the customer is entitled to a full refund
regardless of the return date. Additionally, if the product is part of a limited edition or
clearance sale, the return is not allowed after 30 days.
Write a function that checks the refund eligibility based on the return date, damage status,
and product type.
Input:
● Return days: 45
● Is the product damaged?: "Yes"
● Product type: "Clearance Sale"
Expected Output:
● "Full refund. Product is damaged."

3. A parking authority calculates fines based on the type of parking violation:


● If the car is parked in a no parking zone, the fine is $100.
● If the car is parked in a loading zone during restricted hours (9 AM - 6 PM), the fine
is $75.
● If the car is parked in a handicapped spot without a permit, the fine is $200.
● If the car is parked over the time limit in a metered spot, the fine is $50 for every
hour the car is over the limit.
Write a function that calculates the fine based on the violation type and, if applicable, the
time over limit.
Input:
● Violation type: "Handicapped Spot"
● Time over limit: None
Expected Output:
● "Fine: $200. You parked in a handicapped spot without a permit."

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."

14. An employee’s salary bonus is calculated based on:


● Job performance rating (Excellent, Good, Fair, Poor):
○ If the rating is Excellent, the bonus is 20% of the salary.
○ If the rating is Good, the bonus is 10% of the salary.
○ If the rating is Fair, the bonus is 5% of the salary.
○ If the rating is Poor, no bonus is given.
● However, employees with more than 10 years of service get an additional $1000
bonus, regardless of the rating.
Write a function to calculate the bonus based on the employee’s rating and years of service.
Input:
● Rating: "Good"
● Salary: $50,000
● Years of service: 12
Expected Output:
● "Your bonus is $6000, including the service bonus."

15. An ATM withdrawal system limits users based on:


● If the user is withdrawing less than $500, no service charge is applied.
● If the user is withdrawing between $500 and $1000, a $10 fee is applied.
● If the withdrawal is more than $1000, a $25 fee is applied.
● Additionally, users with an account balance below $100 cannot withdraw more than
$50.
Write a function to calculate the total withdrawal amount (including any fees) based on the
amount to withdraw and account balance.
Input:
● Amount to withdraw: $1200
● Account balance: $1300
Expected Output:
● "Your total withdrawal amount is $1225, including the $25 service fee."

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 :

Cost price (in Rs) Tax


> 100000 15 %
> 50000 and <= 100000 10%
<= 50000 5%

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)

8. Write a program to accept a number from 1 to 12 and display name of the


month and days in that month like 1 for January and number of days 31 and so
on

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.

11. A company decided to give bonus to employee according to following criteria:


Time period of Service Bonus
More than 10 years 10%
>=6 and <=10 8%
Less than 6 years 5%
Ask user for their salary and years of service and print the net bonus amount.

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%

>7000 and <=10000 15%


<=7000 10%

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

>=18 and <30 M 700

F 750

>=30 and <=40 M 800

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.

1. Write a program to accept two numbers and mathematical operators and


perform operation accordingly.
Like:

Enter First Number: 7


Enter Second Number : 9
Enter operator : +
Your Answer is : 16
2. Write a Python program that asks for the user’s age and prints "Child" if under 12,
"Teen" if between 13 and 19, and "Adult" if 20 or older.

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.

7. Write a Python program that prints "Fizz" if a number is divisible by 3, "Buzz" if


divisible by 5, and "FizzBuzz" if divisible by both. If not divisible by either, print the
number itself.

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

for i in range(5): for i in range(10,15): for i in (5,9):


print(i) print(i) print(i)

for i in "vituniversity": for i in range(2,15,2): for i in "python":


print(i) print(i) print(i, end=' ')

for i in "Myblog": for i in "python": for i in (3,4,7):


print (i, '?') print(i, '?$') print(i)
for i in "python":

print(i, end=='?')

Q2. Write the output of the following code :

x=5 a=7 b=5


while(x<15): b=5 while(b<9):
print(x**2) while(a<9): print("H")
x+=3 print(a+b) b+=1
a+=1

b=15 x=15 x = "123"


while(b>9): while(x==15): for i in x:
print("Hello") print("Hello") print("a")
b=b-2 x=x-3

i=9 a=6 i=0


while True: while(a<=10): while i<3:
if i%3==0: print("a") print(i)
break a+=1 i=i+1
print("A") else:
print(7)

i=0 i=2 i=2


while i<3: for x in range(i): for x in range(i):
print(i) i+=1 x+=1
i=i+1 print(i) print(x)
print(0) print(i) print(x)

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 print first 10 natural number.

Write a program to print first 10 even numbers.

Write a program to print first 10 odd numbers.

Write a program to print first 10 even numbers in reverse order.

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 print numbers from 1 to 20 except multiple of 2 & 3.

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 convert temperature in Fahrenheit to Celsius.

Write a program to print table of a number accepted from user.

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 factorial of a number.

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 check whether a number is prime or not.

Write a program to print all prime numbers that fall between two
numbers including both(accept two numbers from the user)

Write a program to print table of a number(accepted from user) in the


following format.
Like : input number is 7, so expected output is
7*1=7
7 * 2 = 14 and so on

Write a program that keep on accepting number from the user until user
enters Zero. Display the sum and average of all the numbers.

Accept a number and check whether it is palindrome or not.

Write a program to accept a number and check whether it is a perfect


number or not.
(Perfect number is a positive integer which is equal to the sum of its
divisors like divisors of 6 are 1,2,3, and
sum of divisors is also 6, so 6 is the perfect number)

Write a program to find the sum of the following series(accept values of


x and n from user)
Write a program to find the sum of following (Accept values of a, r, n
from user)
a + ar + ar2 + ar3 + ………..arn

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

You might also like