Question: Question C 2 [ 1 0 marks ] Write your answer in the provided file A 3 Q 2 . py . Fill in your

Question C2[10 marks]
Write your answer in the provided file A3Q2. py. Fill in your name and student ID in the designated section.
This application is used in a fruit store to calculate the amount spent on each order, maintain records, and generate a daily report or log file for all orders.
The fruit names and their corresponding prices (per gram) are stored in a text file named "productsList. txt" with the format "=". Each line in the file contains one 'fruit-price' pair, as shown in the sample below:
To implement this application, you need to define a few functions:
1. Write a function read_data() with the filename as the input parameter and return a list of strings holding all contents of this file.
2. Write a function list_to_dict() with aList as input parameter and return a dictionary. Below is test case for this function:
```
>>> listTest =['Fruit 1=0.02
','Fruit 2=0.03
','Fruit 3=0.04
']
>>> dictTest=list_to_dict(listTest)
>>> print(dictTest)
{'Fruit 1': 0.02, 'Fruit 2': 0.03, 'Fruit 3': 0.04}
```
3. Write a function cust_spend) with adict as parameter. Iterate through all the item keys in the dictionary adict, and prompt the user to enter the weight (in grams) for each fruit. The function should calculate the total amount of the order and return it as an output in float format. Below is the test case for this function:
```
>>> f_test=cust_spend(dictTest)
How many grams of the fruit 'Fruit 1'[price:0.02]?100
How many grams of the fruit 'Fruit 2'[price:0.03]?100
How many grams of the fruit 'Fruit 3'[price:0.04]?100
>>> print(f_test)
9.0
```
4. Write a function main() as the main loop of this application. Inside the main() function, do the following:
a. Load the fruit-price information by opening the given text file "productsList.txt" and reading the contents into a variable ls_allPrices as a list.
b. Convert this list to a dictionary dict_ProductPrice by calling the corresponding function.
c. Use a while True loop to ask the user for customer ID, and store it in a variable customerID. Print the greeting messages (see the sample output) and ask the user to enter the weights for each fruit (by calling the cust_spend () function). Print the total amount of the order. Exit this loop when the user enters the word 'end'.
d. Store each order in a tuple with the format "," Create a variable todayOrder as a list and add each tuple record to the list todayOrder.
e. Display the variable todayOrder after the user entered the word 'end' as a customerID. The total amount should be displayed with 2 decimal places.
5. The program output should adhere to the Sample Output provided below:
Sample Output 1:
```
Completed by student Chan Siu Ming with student ID 40202425.
Please enter your customer ID [type 'end' to exit]: 1001
Hi,1001! Please enter the weight[in grams] for each fruit:
How many grams of the fruit 'Apple'[price:0.04]?100
How many grams of the fruit 'Banana'[price:0.15]?100
How many grams of the fruit 'Grape'[price:0.1]?100
Thank you, 1001! You have spent $29.00 in this order.
Please enter your customer ID [type 'end' to exit]: 1002
Hi,1002! Please enter the weight[in grams] for each fruit:
How many grams of the fruit 'Apple'[price:0.04]?10
How many grams of the fruit 'Banana'[price:0.15]?10.05
How many grams of the fruit 'Grape'[price:0.1]?10.5
Thank you, 1002! You have spent $2.96 in this order.
Please enter your customer ID [type 'end' to exit]: end
Today's orders: [('1001','29.00'),('1002','2.96')]
```
Sample Output 2(No order has been made.).
```
Completed by student Chan Siu Ming with student ID 40202425.
Please enter your customer ID [type 'end' to exit]: end
Today's orders: []
```
Note:
- All user inputs are in green.
- Assume the user inputs for the weights are all in numeric data types.
- Assume the provided file "productsList. txt" contains the sample data and exists in the same directory as the Python file A3Q2. py.
- Ensure that all mentioned variables (1s_allPrices, todayOrder, dict_ProductPrice, customerID) are used and assigned appropriate values.
Hint: Refer to the general guidelines to determine how to call the main () function.
Question C 2 [ 1 0 marks ] Write your answer in

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!