V.Vidhya Logo

V.Vidhya

Dictionaries & Tuples


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 subjects and their marks in a dictionary, then prints the marks obtained in Maths and finally prints the total marks for all subjects.

No need to take user input. Just pre-initialise the values in the list.

Expected Output:

// subject marks: Maths:85, English: 90, Science:78, History:88, Geography:80

Marks obtained in Maths: 85
Total marks: 421

Q3.

A farmer monitors soil moisture across multiple fields each morning to detect dry spots before they stress the crops. They need a simple program that reports current readings, flags fields below a critical threshold and then simulates irrigation by boosting those levels.

Instructions

Write a program that stores and manages current soil moisture readings (%) for five fields (No need to take user input), then:

  • Print the moisture level for each field.
  • For every field whose reading is below 30%, print an alert message saying “Irrigation needed”.
  • Irrigate those dry fields by adding 20% to their moisture readings.
  • Finally, print the updated moisture levels for all fields.
Expected Output
// soil_moisture: Field-1:45, Field-2:28, Field-3:33, Field-4:25, Field-5:50

Soil moisture readings:
Field-1: 45%
Field-2: 28%
Field-3: 33%
Field-4: 25%
Field-5: 50%

Irrigation needed at Field-2
Irrigation needed at Field-4

Updated moisture after irrigation:
Field-1: 45%
Field-2: 48%
Field-3: 33%
Field-4: 45%
Field-5: 50%

Q4.

What will be the output of the following programs?

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


Q5.

A writer is polishing their story and worries that certain words may be overused. To help, write a program where, user will type in the paragraph and then list the common stop-words they want the program to ignore. The program will then reports the five words that appear most frequently outside of the stop-word list.

Expected Output
// input
Enter your text: 
His followers called him Mahasamatman and said he was a god. He preferred to drop the Maha 
and the atman, however, and called himself Sam. He never claimed to be a god. But then, 
he never claimed not to be a god.

Enter stop-words (separated by spaces):
he a the and to of in was is but

// output
god: 3
called: 2
claimed: 2
never: 2
followers: 1

Q6. (Adv.)

A small business owner needs a digital contact manager to keep track of clients’ multiple phone numbers and emails, allowing staff to quickly add, remove or update client details and always have an up-to-date, alphabetized directory.

Instructions
  • Pre-initialize a contacts dictionary with three sample entries, each mapping a person’s name to another dict with:
    • phones: a list of one or more phone-number strings
    • email: their email address string
  • Present a menu to the user with options:
    • Add a new contact: prompt for name, one phone and email
    • Remove a contact:
    • Update a contact: prompt for name and a new phone, append it to that contact’s phones list (print “Not found” if missing).
    • Display all contacts: print all contacts sorted alphabetically by name
    • Exit
  • Use dictionary methods and checks for clean lookups and updates
Expected Output
// Initial Contacts:
Lukasz Langa: phones: 9876543210, 8765432109, email: [email protected]
Daniel Feldroy: phones: 9123456780, email: [email protected]
Doug Hellmann: phones: 9988776655, email: [email protected]

### MENU: ###
1. Add contact
2. Delete contact
3. Update contact
4. Display contacts
5. Exit

Enter choice: 4

Contacts list:
# Daniel Feldroy:
   Phones: 9123456780
   Email: [email protected]
# Doug Hellmann:
   Phones: 9988776655
   Email: [email protected]
# Lukasz Langa:
   Phones: 9876543210, 8765432109
   Email: [email protected]

### MENU: ###
1. Add contact
2. Delete contact
3. Update contact
4. Display contacts
5. Exit

Enter choice: 1
Enter name: Matt Layman
Enter phone: 7856985642
Enter email: [email protected]
Contact 'Matt Layman' added.

### MENU: ###
1. Add contact
2. Delete contact
3. Update contact
4. Display contacts
5. Exit

Enter choice: 4

Contacts list:
# Daniel Feldroy:
   Phones: 9123456780
   Email: [email protected]
# Doug Hellmann:
   Phones: 9988776655
   Email: [email protected]
# Lukasz Langa:
   Phones: 9876543210, 8765432109
   Email: [email protected]
# Matt Layman:
   Phones: 7856985642
   Email: [email protected]

### MENU: ###
1. Add contact
2. Delete contact
3. Update contact
4. Display contacts
5. Exit

Enter choice: 2
Enter name: Doug Hallmann
Not found.

### MENU: ###
1. Add contact
2. Delete contact
3. Update contact
4. Display contacts
5. Exit

Enter choice: 2
Enter name: Doug Hellmann   
Contact 'Doug Hellmann' deleted.

### MENU: ###
1. Add contact
2. Delete contact
3. Update contact
4. Display contacts
5. Exit

Enter choice: 3
Enter name: Daniel Feldroy
Enter new phone: 9898757564
Phone number added for 'Daniel Feldroy'.

### MENU: ###
1. Add contact
2. Delete contact
3. Update contact
4. Display contacts
5. Exit

Enter choice: 4

Contacts list:
# Daniel Feldroy:
   Phones: 9123456780, 9898757564
   Email: [email protected]
# Lukasz Langa:
   Phones: 9876543210, 8765432109
   Email: [email protected]
# Matt Layman:
   Phones: 7856985642
   Email: [email protected]

### MENU: ###
1. Add contact
2. Delete contact
3. Update contact
4. Display contacts
5. Exit

Enter choice: 5
Program closed!

Q7.

What will be the output of the following programs?

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


Q8. (Adv.)

A regional farmers’ co-op reviews weekend market performance to spot top sellers and customer satisfaction. For that, they need an interactive tool to summarize sales, identify popular products and track vendor ratings on the fly.

Instructions

Your program should present a simple menu that lets users:

  • View comprehensive sales and rating summaries
  • Enter a live update (vendor name, product, quantity, rating)
  • After each action, it must recalculate and display:
    • Total units sold per vendor
    • Aggregate sales per product and the top-selling item
    • Each vendor’s average customer rating and list those rated 4.0 or higher
Expected Output
Welcome to the Farmers' Co-op Market Performance Tracker!

==================================================
FARMERS' CO-OP MARKET PERFORMANCE TRACKER
==================================================
1. View comprehensive sales and rating summaries
2. Enter a live update (vendor, product, quantity, rating)
3. Exit program
--------------------------------------------------
Enter your choice (1-3): 1

--------------------------------------------------
COMPREHENSIVE MARKET PERFORMANCE SUMMARY
--------------------------------------------------

TOTAL UNITS SOLD PER VENDOR:
----------------------------------------
  Agrim Farms             77 units
  Freshnet Agro           50 units
  Swasthya Baag           43 units

TOP-SELLING PRODUCT:
----------------------------------------
  Tomatoes - 45 units sold

ALL PRODUCT SALES:
----------------------------------------
  Tomatoes                 45 units
  Apples                   38 units
  Lettuce                  32 units
  Cheese                   25 units
  Milk                     18 units
  Honey                    12 units

VENDOR RATINGS:
----------------------------------------
  Swasthya Baag         4.73/5.0
  Agrim Farms           4.50/5.0
  Freshnet Agro         4.10/5.0

HIGHLY RATED VENDORS (4.0+):
----------------------------------------
  Swasthya Baag         4.73/5.0
  Agrim Farms           4.50/5.0
  Freshnet Agro         4.10/5.0


==================================================
FARMERS' CO-OP MARKET PERFORMANCE TRACKER
==================================================
1. View comprehensive sales and rating summaries
2. Enter a live update (vendor, product, quantity, rating)
3. Exit program
--------------------------------------------------
Enter your choice (1-3): 2

--------------------------------------------------
ADD LIVE MARKET UPDATE
--------------------------------------------------
Enter vendor name: Freshnet Agro
Enter product name: Apples
Enter quantity sold: 35
Enter customer rating (1.0-5.0): 3.45
Successfully added: 35 units of Apples from Freshnet Agro (Rating: 3.45/5.0)

Updated Market Summary:
----------------------------------------

Total units by vendor:
  Freshnet Agro: 85 units
  Agrim Farms: 77 units
  Swasthya Baag: 43 units

Top-selling product: Apples (73 units)

Vendors rated 4.0+:
  Swasthya Baag: 4.73/5.0
  Agrim Farms: 4.50/5.0


==================================================
FARMERS' CO-OP MARKET PERFORMANCE TRACKER
==================================================
1. View comprehensive sales and rating summaries
2. Enter a live update (vendor, product, quantity, rating)
3. Exit program
--------------------------------------------------
Enter your choice (1-3): 2

--------------------------------------------------
ADD LIVE MARKET UPDATE
--------------------------------------------------
Enter vendor name: Malabar Farms
Enter product name: Tomatoes
Enter quantity sold: 20
Enter customer rating (1.0-5.0): 4.15
Successfully added: 20 units of Tomatoes from Malabar Farms (Rating: 4.15/5.0)

Updated Market Summary:
----------------------------------------

Total units by vendor:
  Freshnet Agro: 85 units
  Agrim Farms: 77 units
  Swasthya Baag: 43 units
  Malabar Farms: 20 units

Top-selling product: Apples (73 units)

Vendors rated 4.0+:
  Swasthya Baag: 4.73/5.0
  Agrim Farms: 4.50/5.0
  Malabar Farms: 4.15/5.0


==================================================
FARMERS' CO-OP MARKET PERFORMANCE TRACKER
==================================================
1. View comprehensive sales and rating summaries
2. Enter a live update (vendor, product, quantity, rating)
3. Exit program
--------------------------------------------------
Enter your choice (1-3): 2       

--------------------------------------------------
ADD LIVE MARKET UPDATE
--------------------------------------------------
Enter vendor name: Malabar Farms
Enter product name: Onions
Enter quantity sold: 25
Enter customer rating (1.0-5.0): 3.24
Successfully added: 25 units of Onions from Malabar Farms (Rating: 3.24/5.0)

Updated Market Summary:
----------------------------------------

Total units by vendor:
  Freshnet Agro: 85 units
  Agrim Farms: 77 units
  Malabar Farms: 45 units
  Swasthya Baag: 43 units

Top-selling product: Apples (73 units)

Vendors rated 4.0+:
  Swasthya Baag: 4.73/5.0
  Agrim Farms: 4.50/5.0


==================================================
FARMERS' CO-OP MARKET PERFORMANCE TRACKER
==================================================
1. View comprehensive sales and rating summaries
2. Enter a live update (vendor, product, quantity, rating)
3. Exit program
--------------------------------------------------
Enter your choice (1-3): 1

--------------------------------------------------
COMPREHENSIVE MARKET PERFORMANCE SUMMARY
--------------------------------------------------

TOTAL UNITS SOLD PER VENDOR:
----------------------------------------
  Freshnet Agro           85 units
  Agrim Farms             77 units
  Malabar Farms           45 units
  Swasthya Baag           43 units

TOP-SELLING PRODUCT:
----------------------------------------
  Apples - 73 units sold

ALL PRODUCT SALES:
----------------------------------------
  Apples                   73 units
  Tomatoes                 65 units
  Lettuce                  32 units
  Cheese                   25 units
  Onions                   25 units
  Milk                     18 units
  Honey                    12 units

VENDOR RATINGS:
----------------------------------------
  Swasthya Baag         4.73/5.0
  Agrim Farms           4.50/5.0
  Freshnet Agro         3.94/5.0
  Malabar Farms         3.70/5.0

HIGHLY RATED VENDORS (4.0+):
----------------------------------------
  Swasthya Baag         4.73/5.0
  Agrim Farms           4.50/5.0

Press Enter to continue...

==================================================
FARMERS' CO-OP MARKET PERFORMANCE TRACKER
==================================================
1. View comprehensive sales and rating summaries
2. Enter a live update (vendor, product, quantity, rating)
3. Exit program
--------------------------------------------------
Enter your choice (1-3): 3

Thank you for using the Market Performance Tracker!
Have a great market day!

Q9.

What will be the output of the following programs?

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


Q10.

You’re building a World Treasure Map assistant program. When an explorer types the name of a famous treasure/place, the program should return the place’s GPS coordinates.

Expected Output:

// case 1
Enter place name: Taj Mahal
Found! Taj Mahal at latitude 27.1751 and longitude 78.0421

// case 2
Enter place name: Hampi
Not Found! Sorry, Hampi is not in our database.

Q11. (Adv.)

You’re on the event planning team and must build a simple, menu-driven event helper so staff can add school events, check a date, list all events and find the next event.

Instructions

Your program should present a simple menu that lets users:

  • Add event: prompt for date (YYYY MM DD) and event name
  • Check event by date: prompt for date and show the corresponding event
  • List all events: print all date-event pairs sorted chronologically
  • Next event after date: prompt for date and print the next occuring event after that date
Expected Output
### MENU: ###
1. Add event
2. Check event by date
3. List all events
4. Next event after date
5. Exit
Choose option: 3
All event dates:
2025/03/21 - Spring Fair
2025/08/16 - Janmashtami Celebration
2025/12/25 - Winter Feast

### MENU: ###
1. Add event
2. Check event by date
3. List all events
4. Next event after date
5. Exit
Choose option: 1
Enter date (YYYY MM DD): 2026 1 14
Enter event description: Kite Festival

### MENU: ###
1. Add event
2. Check event by date
3. List all events
4. Next event after date
5. Exit
Choose option: 2
Enter date (YYYY MM DD): 2025 8 16
Found! 2025/08/16 - Janmashtami Celebration

### MENU: ###
1. Add event
2. Check event by date
3. List all events
4. Next event after date
5. Exit
Choose option: 2
Enter date (YYYY MM DD): 2025 6 7
No event on 2025/06/07

### MENU: ###
1. Add event
2. Check event by date
3. List all events
4. Next event after date
5. Exit
Choose option: 4        
Enter date (YYYY MM DD): 2025 7 30
Next event on 2025/12/25 - Winter Feast

### MENU: ###
1. Add event
2. Check event by date
3. List all events
4. Next event after date
5. Exit
Choose option: 5
Exiting program. Goodbye!

Prev Post
Images
Next Post
Graphics, Animations & UI