Q1.
What will be the output of the following programs?
You have to predict the output result without running/executing the code.
I.
numbers = [4.7, -6.0, 0.22, 1.6] print(numbers[0]) numbers[2] = 0.35 print(numbers[2])II.
student_details = [17, 'rancho', -5.5, True, 'F'] print(student_details[-2]) print(student_details[5])III.
sentence = ['lots', 'of', 'strings', 'in', 'list'] print(sentence) for word in range(len(sentence)): print(sentence[word], end=' ')IV.
numbers = [] print(numbers) numbers[0] = 1 print(numbers[0])V.
number_list = [1] number_var = 1 if number_list == number_var: print("list is equal to one") else: print("list is not equal to one")
Q2.
Write a program that stores five grocery item names in one list and prints the last item from grocery list, then stores their prices in a second list and prints the second item from price list.
No need to take user input. Just pre-initialise the values in the list.
Expected Output:
// item names: salt, banana, potato, butter, honey
// item prices: 200, 30, 150, 75, 325
Name of the last item: honey
Price of the second item: rs.30Q3.
Write a program that allows a teacher to enter a student’s marks for 5 subjects, then displays all the marks, total and percentage.
Expected Output:
// input
Enter marks of
subject1: 75
subject2: 65
subject3: 80
subject4: 67
subject5: 73
// output
Student Marks for
subject1: 75
subject2: 65
subject3: 80
subject4: 67
subject5: 73
Total: 360
Percentage: 72Q4.
What will be the output of the following programs?
You have to predict the output yourself without running/executing the code.
I.
letters = ['a', 'b', 'c', 'd', 'e'] letters.append('f') print(letters) letters.append('g', 'h') print(letters)II.
letters = ['a', 'b', 'c', 'd', 'e', 'f'] letters.pop() print(letters) l = letters.pop(2) print(l) print(letters) k = letters.pop(9) print(k) print(letters) letters.pop(-1) print(letters) letters.pop('b') print(letters)III.
letters = ['a', 'b', 'd'] i = letters.index('b') letters.insert((i + 1), 'c') print(letters) j = letters.index('e') print(j) letters.insert(-2, 'e') print(letters) letters.insert('f', 4) print(letters)IV.
letters = ['a', 'b', 'c', 'd', 'e'] letters.remove('b') print(letters) l = letters.remove('d') print(letters) print(l) letters.remove(2) print(letters) letters.remove('f') print(letters)
Q5.
Write a program that stores the temperatures (in celsius) of a city for a week (7 days) in a list. Allow the user to enter the temperatures and then:
- Display all recorded temperatures.
- Find and display the average temperature.
- Identify and display the highest and lowest temperatures.
Expected Output:
// input
Enter the temperature (°C) for
day1: 31
day2: 29
day3: 33
day4: 27
day5: 30
day6: 25
day7: 28
// output
Temperatures for
day1: 31°C
day2: 29°C
day3: 33°C
day4: 27°C
day5: 30°C
day6: 25°C
day7: 28°C
Average Temperature (°C): 29
Lowest Temperature of the week (°C): 25 on day6
Highest Temperature of the week (°C): 33 on day3Q6.
What will be the output of the following programs?
You have to predict the output yourself without running/executing the code.
I.
marks = [87, 66, 79] marks_backup = marks.copy() marks.append(90) print(marks) print(marks_backup) marks_backup = marks marks.append(95) print(marks) print(marks_backup)II.
even_numbers = [2, 4, 6, 8, 10] odd_numbers = [1, 3, 5, 7, 9] all_numbers = even_numbers + odd_numbers print("All numbers:", all_numbers) special_numbers = [0, -1] all_numbers += special_numbers print("All numbers:", all_numbers) extra_numbers = special_numbers * 2 print("Extra numbers:", extra_numbers) all_numbers = even_numbers - odd_numbers print("All numbers:", all_numbers)III.
guest_list = ["hema", "rekha"] guest_list_extra = ["jaya", "sushma"] guest_list.extend(guest_list_extra) print(guest_list) print(guest_list_extra) guest_list_final = guest_list.extend("nirma") print(guest_list) print(guest_list_final)IV.
scores = [98, 87, 76, 99, 88, 73, 92] scores.sort() print(scores) names = ['ollie', 'holly', 'molly', 'dolly', "paulie", "polly"] names.sort() print(names)V.
sections = ['A', 'B', 'C', 'D'] user_section = 'E' if user_section in sections: print("There is a section E") else: print("There is no section E") students = [] if students: print("There are students") else: print("There are no students")
Q7.
A teacher wants to analyze how students performed in a multiple-choice test with 10 questions. The correct answers are stored in a list. The teacher then inputs a student’s answers into another list. Your program should:
- Display how many answers are correct.
- Give the student’s score. (Each correct answer is worth 10 marks.)
Expected Output:
// correct answers
correct-answers: A, B, C, D, A, B, C, D, A, B
// input
Enter student answers: A B D D A C C D B B
// output
Total correct answers: 7
Score: 70Q8.
A streaming service has just released a new movie and collected star-ratings from viewers. Your program should:
- Read in the
N(whereN> 15) ratings (each a number from 1 to 5). - Calculate and display, for each rating level, the number of votes received and the percentage of the total votes.
Expected Output:
// input
Enter 20 ratings (1 - 5):
1 3 3 4 2 2 2 3 4 3 1 4 3 4 5 2 3 3 4 5
// output
Rating distribution:
1 star: 2 votes (10%)
2 star: 4 votes (20%)
3 star: 7 votes (35%)
4 star: 5 votes (25%)
5 star: 2 votes (10%)Q9.
A popular arcade game keeps a list of the five highest scores ever achieved, in descending order. Now they want to automate updating this leaderboard whenever a new score arrives.
Instructions
- Take the five previous scores as user input (in any order).
- Sort them into descending order.
- Take a new player’s score as user input.
- Then update the top five scores in descending order. (When a new score comes in, it needs to be added to that list in the right place and the lowest score dropped if there are more than five.)
Expected Output
// input
Enter the previous 5 scores: 72 99 68 87 93
// output
High-score list:
1. 99
2. 93
3. 87
4. 72
5. 68
// input
Enter the new score:
75
// output
High-score list:
1. 99
2. 93
3. 87
4. 75
5. 72Q10. (Adv.)
You are shopping for 5 items, each with a known price. The store offers a discount coupon that costs X rupees and reduces the price of every item by Y rupees. If an item’s price is Y or less, it becomes free.
Decide whether you should buy the coupon or not. You should buy it only if the total cost after applying the discount (including the coupon’s price) is strictly less than the total cost without the coupon.
Write a program that takes X and Y as input, followed by the prices of 5 items and prints “DO use coupon” if buying the coupon is beneficial, otherwise “DO NOT use coupon”.
Expected Output
// input
Enter the coupon price (rs): 30
Enter the discount price of the coupon (rs): 15
Enter prices (rs) of
item1: 10
item2: 40
item3: 100
item4: 25
item5: 65
// output
DO use coupon
// explanation
// Total cost of items: 10 + 40 + 100 + 25 + 65 = 240
// Total cost (after applying coupon):
// item1: (10 - 15) = free
// item2: (40 - 15) = 25
// item3: (100 - 15) = 85
// item4: (25 - 15) = 10
// item5: (65 - 15) = 50
// 0 + 25 + 85 + 10 + 50 = 170
// Total cost with discount + coupon price = 170 + 30 = 200
// Total cost without coupon: 240
// 200 < 240, so it is beneficial to use the coupon.Q11.
A group of friends is playing a classic Tic-Tac-Toe game. The game is played on a 3x3 grid, where each cell can either be empty (.), filled with X or O.
As the game progresses, they need a way to store the current state of the game board and update it after each move.
At this moment, the game board looks like this:
X O X
. . O
X . .
// grid cell numbers
// 1 2 3
// 4 5 6
// 7 8 9- Your task is to: store this current state into a game data-set and display it on the screen.
Now, it’s player O’s turn, and they want to place their mark in the middle row, first position i.e. cell number 4.
- Your next task is to: update the board with the new move and again display the updated game board after the move.
Q12.
An air-quality station in your city measures the fine particulate concentration (PM2.5 in µg/m³) at four different times of the day: morning, noon, evening and night. The station collects this data every day for a full week.
Write a program that:
- Store the daily temperature readings by taking input from user.
- Allows the user to check the average PM2.5 reading for any given day.
- Identify the highest and lowest PM2.5 reading recorded during the week and display at what time of the day they occurred.
Expected Output
Enter PM2.5 readings for each day and time:
-------------------------------------------------
Day 1:
--------
Morning: 22
Noon: 24
Evening: 23
Night: 21
Day 2:
--------
Morning: 24
Noon: 26
Evening: 25
Night: 24
Day 3:
--------
Morning: 23
Noon: 27
Evening: 26
Night: 25
Day 4:
--------
Morning: 26
Noon: 29
Evening: 28
Night: 25
Day 5:
--------
Morning: 29
Noon: 33
Evening: 30
Night: 28
Day 6:
--------
Morning: 30
Noon: 33
Evening: 32
Night: 31
Day 7:
--------
Morning: 26
Noon: 27
Evening: 25
Night: 23
-------------------------------------------------
Enter the day number (1-7) to get the average PM2.5 concentration: 4
Average PM2.5 on Day 4: 27 µg/m³
-------------------------------------------------
Highest PM2.5 of the week: 33 µg/m³ on Day 5 (Noon)
Lowest PM2.5 of the week: 21 µg/m³ on Day 1 (Night)Q13. (Adv.)
A small cinema hall has a fixed seating arrangement with multiple rows (5) and columns (6). Some seats are already booked, while others are available.
Develop a seat booking system where:
- The user can check seat availability before buying a ticket. (Initially all seats are available.)
- A user can select a seat, and if it’s available, it gets booked automatically. (Ensure that your system does not allow booking of an already occupied seat.)
- Display the updated seating chart after each booking.
Expected Output
# Options:
1. Display Seating Chart
2. Check Seat Availability
3. Book a Seat
4. Exit
----------------
Enter your choice: 1
Current Seating Chart:
1 2 3 4 5 6
-------------
1 | O O O O O O
2 | O O O O O O
3 | O O O O O O
4 | O O O O O O
5 | O O O O O O
----------------
# Options:
1. Display Seating Chart
2. Check Seat Availability
3. Book a Seat
4. Exit
----------------
Enter your choice: 2
Enter row (1-5) and column (1-6) to check availability: 3 4
Seat is available.
----------------
# Options:
1. Display Seating Chart
2. Check Seat Availability
3. Book a Seat
4. Exit
----------------
Enter your choice: 3
Enter row (1-5) and column (1-6) to book: 5 3
Seat booked successfully!
Current Seating Chart:
1 2 3 4 5 6
-------------
1 | O O O O O O
2 | O O O O O O
3 | O O O O O O
4 | O O O O O O
5 | O O X O O O
----------------
# Options:
1. Display Seating Chart
2. Check Seat Availability
3. Book a Seat
4. Exit
----------------
Enter your choice: 2
Enter row (1-5) and column (1-6) to check availability: 5 3
Seat is already occupied.
----------------
# Options:
1. Display Seating Chart
2. Check Seat Availability
3. Book a Seat
4. Exit
----------------
Enter your choice: 3
Enter row (1-5) and column (1-6) to book: 5 3
Seat is already occupied. Please choose another seat.
Current Seating Chart:
1 2 3 4 5 6
-------------
1 | O O O O O O
2 | O O O O O O
3 | O O O O O O
4 | O O O O O O
5 | O O X O O O
----------------
# Options:
1. Display Seating Chart
2. Check Seat Availability
3. Book a Seat
4. Exit
----------------
Enter your choice: 4
Exiting the system.Q14. (Adv.)
A hospital consists of multiple floors (3), each with a certain number of rooms (2) and each room has a fixed number of beds (4). Due to rising patient intake, the hospital administration wants to efficiently manage the availability of beds across all floors.
Your task is to develop a program that:
- Keeps track of which beds are occupied or vacant in each room.
- Allows hospital staff to check bed availability for a given room and floor.
- Displays the total number of vacant beds in the hospital at any time.
The hospital needs a solution to avoid overbooking beds and improve efficiency.
Expected Output
----------------
# Options:
1. Display Bed Status
2. Check Bed Availability
3. Book a Bed
4. Display Total Vacant Beds
5. Exit
----------------
Enter your choice: 1
Current Bed Status:
Floor 1:
Room 1: O O O O
Room 2: O O O O
Floor 2:
Room 1: O O O O
Room 2: O O O O
Floor 3:
Room 1: O O O O
Room 2: O O O O
----------------
# Options:
1. Display Bed Status
2. Check Bed Availability
3. Book a Bed
4. Display Total Vacant Beds
5. Exit
----------------
Enter your choice: 2
Enter floor (1-3) and room (1-2) to check availability: 2 1
Bed availability in Floor 2, Room 1:
Bed 1 is available.
Bed 2 is available.
Bed 3 is available.
Bed 4 is available.
----------------
# Options:
1. Display Bed Status
2. Check Bed Availability
3. Book a Bed
4. Display Total Vacant Beds
5. Exit
----------------
Enter your choice: 3
Enter floor (1-3), room (1-2), and bed (1-4) to book: 2 1 3
Bed booked successfully!
----------------
# Options:
1. Display Bed Status
2. Check Bed Availability
3. Book a Bed
4. Display Total Vacant Beds
5. Exit
----------------
Enter your choice: 1
Current Bed Status:
Floor 1:
Room 1: O O O O
Room 2: O O O O
Floor 2:
Room 1: O O X O
Room 2: O O O O
Floor 3:
Room 1: O O O O
Room 2: O O O O
----------------
# Options:
1. Display Bed Status
2. Check Bed Availability
3. Book a Bed
4. Display Total Vacant Beds
5. Exit
----------------
Enter your choice: 4
Total vacant beds in the hospital: 23
----------------
# Options:
1. Display Bed Status
2. Check Bed Availability
3. Book a Bed
4. Display Total Vacant Beds
5. Exit
----------------
Enter your choice: 3
Enter floor (1-3), room (1-2), and bed (1-4) to book: 2 1 3
Bed is already occupied. Please choose another bed.
----------------
# Options:
1. Display Bed Status
2. Check Bed Availability
3. Book a Bed
4. Display Total Vacant Beds
5. Exit
----------------
Enter your choice: 5
Exiting the system.