0% found this document useful (0 votes)
16 views

Comprog-Questions

Questions for computer programming

Uploaded by

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

Comprog-Questions

Questions for computer programming

Uploaded by

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

1.

General Questions About the Code

 What does this program do?


o Answer: The program simulates an Online Shopping System where you can:
 Add products and customers
 View products and customers
 Allow customers to buy products
 Save data to a file or perform cleanup actions (e.g., remove products with no stock or
inactive customers).
 What are the main functionalities of your code?
o Answer:

1. Add products or customers.


2. View or update product and customer details.
3. Simulate buying a product, including adding to a cart and managing stock.
4. Save the current state of the system to a file or clean up data (e.g., delete products
with no stock).

2. Questions About Specific Functions

Function: addPC()

 What does the addPC() function do?


o Answer: It allows the user to:
 Add a product with a unique product code, name, category, price, and stock.
 Add a customer with a unique customer ID, name, and contact information.
 Why do you use random.randint(1000, 9999)?
o Answer: To generate unique codes (product codes and customer IDs) automatically.

Function: viewPC()

 How do you view or update products and customers?


o Answer:
 To view, the function prints out all the current products and customers.
 To update, it allows the user to update specific product or customer details based on
their code or ID.
 What happens if the product code or customer ID entered doesn't exist?
o Answer: The program will display "Product not found" or "Customer not found" because of
the else statement in the loop.

Function: buyProduct()

 What happens in the buyProduct() function?


o Answer:
1. It checks if the customer exists using the provided ID.
2. It allows the customer to add products to a "cart".
3. It calculates the total price and confirms the purchase.
4. If confirmed, it deducts the product stock and saves the transaction.
 How do you check if there is enough stock?
o Answer: By comparing the requested quantity (num_items) with the product's current stock
(product["Stock"]).
Function: saveToFile()

 What does the saveToFile() function do?


o Answer:
1. It saves products, customers, and transactions to a file named shop.txt.
2. It can also:
 Remove products with no stock.
 Delete inactive customers (customers who have not made any purchases).
 How do you determine inactive customers?
o Answer: By checking which customers' IDs are not present in the transaction records.

3. Questions About Variables and Data Structures

 What data structures are you using to store products, customers, and transactions?
o Answer: I use lists of dictionaries:
 products list stores dictionaries for each product.
 customers list stores dictionaries for each customer.
 transactions list stores dictionaries for each transaction.
 Why do you use dictionaries?
o Answer: Dictionaries make it easy to organize and store data with key-value pairs (e.g.,
"Code", "Name", etc.), making it efficient to access or update specific information.

4. Possible Logic Questions

 How do you ensure that the product stock decreases when a customer buys something?
o Answer: When a purchase is confirmed, the program iterates through the cart items and
subtracts the purchased quantity from the respective product's stock.
 What happens if a customer tries to buy more items than available stock?
o Answer: The program displays a message saying "Not enough stock available!" and doesn't
allow the purchase.

5. Edge Case Questions

 What happens if there are no products or customers when viewing?


o Answer: The program will print "No Products Available!" or "No Customer Records!" if the
respective lists are empty.
 What if the user enters invalid input (e.g., letters instead of numbers)?
o Answer: The try-except blocks handle invalid inputs, ensuring the program doesn't crash
and prompts the user to try again.

6. File Handling Questions

 Where is the data saved, and what format is it in?


o Answer: Data is saved in a file named shop.txt in a readable format where products,
customers, and transactions are listed.
 What happens if saving to a file fails?
o Answer: The program handles exceptions using a try-except block and prints an error
message if saving fails.

7. Possible Program Flow Questions

 What happens if you exit the program without saving to a file?


o Answer: Any data in the products, customers, or transactions lists will be lost because it
is stored only in memory.
 How can you restart the program after exiting?
o Answer: The program will start fresh, as there is no mechanism to load previous data (unless
you implement one).

You might also like