V.Vidhya Logo

V.Vidhya

Lists


Q1.

What will be the output of the following programs?

You have to predict the output result without running/executing the code.


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

Q3.

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: 72

Q4.

What will be the output of the following programs?

You have to predict the output yourself without running/executing the code.


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:

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 day3

Q6.

What will be the output of the following programs?

You have to predict the output yourself without running/executing the code.


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:

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: 70

Q8.

A streaming service has just released a new movie and collected star-ratings from viewers. Your program should:

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

Q10. (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

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.


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:

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:

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:

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.

Prev Post
Functions
Next Post
Math functions & String Operations