Q1.
Consider the following programs:
I.
BEG
x = 5 if x = 10: print("Hi") else: print("Bye")II.
BEG
x = 5 if x == 5: print("Hi") else print("Bye")III.
BEG
x = 5 if x != 10: print("Hi") else: print("Bye")IV.
BEG
x = 5 if x =< 10: print("Hi") else: print("Bye")V.
BEG
x = 5 if x > 10: else: print("Bye")VI.
BEG
x = 5 if x + 2 > 10: print("Hi")VII.
BEG
x = 5 if x > 10: print("Hi") else: print("Bye")
What will be the output for the programs given above?
You have to predict the output yourself without running/executing the code.
- Hi
- Bye
- Error
- None
Q2.
BEG
At a local bank, customers are allowed to withdraw money without any extra charge as long as the withdrawal amount is less than rs.1000 in a single day. However, if a customer withdraws rs.1000 or more in a day, a small transaction fee is applied. Write a program that asks the customer how much money they want to withdraw today and based on the amount, tells them whether a transaction fee will be applied or not.
Expected Output:
// case 1
Enter withdrawal amount: 750 // user input
A transaction fee will not be applied.
// case 2
Enter withdrawal amount: 2650 // user input
A transaction fee will be applied.Q3.
What will be the output of the following programs?
You have to predict the output yourself without running/executing the code.
I.
BEG
score = 18 total = 20 if not (score < 10 and score >= total): print("Valid score.") else: print("Invalid score.")II.
INT
percentage = 55.63 if (0 <= percentage <= 100): print("This is a valid percentage.") else: print("This is not a valid percentage.")III.
INT
itemsOrdered = 3 totalAmount = 950 if ((totalAmount / itemsOrdered) >= 300) or (itemsOrdered >= 5): print("Delivery Fee Waived") else: print("Delivery Fee Applied")IV.
INT
a = b = 5 if a == b == 5: print("all are 5") else: print("not all are 5")V.
INT
grade = 'D' if grade == 'A' or 'B' or 'C': print("Good") else: print("Bad")
Q4.
BEG
At a stationery shop, pens are packed in boxes of five. Write a program that asks the user for the total number of pens they have and then tells the user whether all the pens will fit into complete boxes or how many pens will be left over after packing.
Expected Output:
// case 1
Enter the total number of pens: 20 // user input
All pens fit into complete boxes - no leftovers!
// case 2
Enter the total number of pens: 64 // user input
You have 4 pen(s) left unpacked.Q5.
What will be the output of the following programs?
You have to predict the output yourself without running/executing the code.
I.
BEG
x = 10 y = 30 if x == 10: if y == 20: print("x is 10 and y is 20") else: print("x is 10 but y is not 20") else: print("x is not 10")II.
BEG
x = 30 if x >= 0: if x <= 20: print(x, "is between 0 and 20") else: print(x, " is negative")III.
BEG
x = -30 if x >= 0: print(f"{x} is positive") else: if (x >= -20): print(f"{x} is between -20 and 0") else: print(f"{x} is less than -20")IV.
BEG
x = 15 y = 30 if x == 10: if y == 20: print("x is 10 and y is 20") else: print("x is 10 but y is not 20")V.
INT
n = '5' if n > 0: print("Positive number") else: print("Zero or negative")
Q6.
BEG
At the airport cargo counter, packages are checked based on their size. Instead of actual weight, they use a volumetric weight formula to decide if the package is too heavy to ship. Write a program that ask the user to enter the length, breadth, and height of the package in cm, then calculate the volumetric weight in kg and finally tells if the package is accepted for shipping or not.
- The formula is:
Volumetric Weight = (Length x Breadth x Height) / 5000 - If the package’s volumetric weight is more than 20 kg then it’s considered too heavy for air shipping.
Expected Output:
// case 1
Enter the length of the package (in cm): 40 // user input
Enter the breadth of the package (in cm): 30 // user input
Enter the height of the package (in cm): 20 // user input
Volumetric weight: 4.8 kg
Package accepted for shipping.
// case 2
Enter the length of the package (in cm): 100 // user input
Enter the breadth of the package (in cm): 80 // user input
Enter the height of the package (in cm): 50 // user input
Volumetric weight: 80.0 kg
Package too heavy for air shipping!Q7.
What will be the output of the following programs?
You have to predict the output yourself without running/executing the code.
I.
BEG
x = 10 y = 20 if x > 5: print('A') elif y > 15: print('B') else: print('C')II.
BEG
age = 25 if age > 18: print("Adult") elif age > 12: print("Teenager") elif age > 5: print("Child") else: print("Toddler")III.
BEG
marks = 90 if marks > 35: print('C') elif marks > 55: print('B') elif marks > 85: print('A') else: print('F')
Q8.
BEG
Write a program that takes an integer from user and checks if that number is even or odd.
Expected Output:
Enter a number: 9 // user input
9 is an odd number.Q9.
BEG
Write a program that asks the user to enter the color of a street light that is currently being shown. Based on the input, display the correct message accordingly:
- red - STOP
- yellow - READY
- green - GO
- any other color - None
Expected Output:
// case 1
Enter the street light color: red // user input
STOP
// case 2
Enter the street light color: blue // user input
NoneQ10.
INT
At the college library, books can be borrowed and returned by students. To manage everything efficiently, they need a system to check students’ borrowing history and pending dues. Write a program that,
- Asks the user if they have borrowed any book or not.
- If they haven’t borrowed any book, they are immediately allowed to borrow a new one.
- If they have borrowed a book, the system then asks how many days it has been since they borrowed it.
- If the number of days is 14 or less, they are allowed to borrow another book.
- If the number of days is more than 14, they are told the number of overdue days and asked to pay a fine of rs.1 per day before they can borrow a new book.
Write a program for this.
Expected Output:
// case 1
Did you borrow any book previously? (yes/no): no // user input
You can borrow a new book. No pending returns.
// case 2
Did you borrow any book previously? (yes/no): yes // user input
How many days ago did you borrow the book?: 10 // user input
Book returned within allowed time. You can borrow a new book.
// case 3
Did you borrow any book previously? (yes/no): yes // user input
How many days ago did you borrow the book?: 20 // user input
Your book return is overdue. You have a pending fine of rs.6.
Please clear the fine before borrowing a new book.Q11.
BEG
A college professor wants to make a student result declaration system. Write a program that takes student percentage as user input and gives student’s result status.
- If a student has less than 35% then he/she fails.
- If a student has more than that there are different achievement levels.
- for more than 75% : Pass with Distinction
- 60-75% : Pass with Merit
- 35-60% : Pass
Expected Output:
Enter student percentage: 65 // user input
Result: Pass with MeritQ12.
BEG
Create a system to calculate popcorn prices based on the bucket size customer asks for:
Here, the list for price per bucket-size is given:
- L : price is rs.200
- M : price is rs.100
- S : price is rs.50
Expected Output:
Enter the popcorn-bucket size: M // user input
Price: 100Q13.
BEG
At a city’s traffic control system, drivers are monitored for speed violations. The city has a strict speed policy - if a driver stays within the speed limit, they can continue without any fine. However, if they exceed the limit, fines are imposed depending on how much they overspeed.
Write a program that asks the driver for their current speed and informs them if they are safe or what fine they need to pay.
- If the speed is 60 km/h or below, no fine is issued.
- If the speed is between 61 and 80 km/h, a fine of rs.500 is issued.
- If the speed is above 80 km/h, a fine of rs.1000 is issued.
Expected Output:
// case 1
Enter your current speed (in km/h): 75 // user input
You have exceeded the speed limit. A fine of rs.500 is applicable.
// case 2
Enter your current speed (in km/h): 95 // user input
You have exceeded the speed limit. A fine of rs.1000 is applicable.Q14.
BEG
For a good and safe paragliding experience as a beginner, certain weather conditions need to be met.
- No raining
- Wind speeds between 5 and 20 km/h
Write a program that checks if it’s a good condition for paragliding or not based on necessary weather parameters taken as user input .
Expected Output:
Is it raining? : false // user input
Wind speeds (km/h) : 12 // user input
It's a good condition for paragliding.Q15.
BEG
Create a program to make a mini-calculator.
Take 2 integer numbers and the operator sign as input from the user, then give the result based on those taken values.
All the arithmetic operators should be covered, i.e. + , - , * , / , %, ^ (power).
Expected Output:
Enter the first number : 3 // user input
Enter the second number : 5 // user input
Choose the operation you want to perform (+, -, *, /, %, ^): * // user input
output: 5 * 3 = 15Q16.
ADV
At the city’s electricity board, household electricity bills are calculated based on the number of units consumed in a month. The board follows a slab system where different rates apply based on consumption levels.
Write a program that asks the user to enter the total number of electricity units consumed for the month, then calculates and displays the final bill amount according to the following rules:
- For the first 100 units, the charge is rs.3 per unit.
- For the next 100 units (units 101 to 200), the charge is rs.4 per unit.
- For any units beyond 200, the charge is rs.5 per unit.
Expected Output:
// case 1
Enter total electricity units consumed: 150 // user input
Electricity Bill: rs.500
// First 100 units: 100 x rs.3 = rs.300, Next 50 units: 50 x rs.4 = rs.200
// Total = rs.300 + rs.200 = rs.500
// case 2
Enter total electricity units consumed: 250 // user input
Electricity Bill: rs.950
// First 100 units: 100 x rs.3 = rs.300, Next 100 units: 100 x rs.4 = rs.400
// Remaining 50 units: 50 x rs.5 = rs.250
// Total = rs.300 + rs.400 + rs.250 = rs.950Q17.
INT
At an international airport’s travel help desk, travellers often want to know the value of their Indian Rupees (INR) in different currencies. Write a program that helps a traveller by converting their amount in INR into a currency of their choice.
Ask the traveller to enter the amount in INR.
Then, ask which currency they want to convert to by selecting an option:
- 1 - US Dollar (USD)
- 2 - Euro (EUR)
- 3 - British Pound (GBP)
- 4 - Chinese Yuan (CNY)
- 5 - Russian Ruble (RUB)
Based on their selection, display the converted amount. Use the following fixed conversion rates:
- 1 INR = 0.012 USD
- 1 INR = 0.011 EUR
- 1 INR = 0.0095 GBP
- 1 INR = 0.087 CNY
- 1 INR = 0.98 RUB
Expected Output
Enter the amount in INR: 7000 // user input
Select the currency to convert to:
1 - US Dollar (USD)
2 - Euro (EUR)
3 - British Pound (GBP)
4 - Chinese Yuan (CNY)
5 - Russian Ruble (RUB)
Your choice (1-5): 2 // user input
Converted amount: 77 EUR