Question: Question C 2 [ 1 0 marks ] Write your answer in the provided file A 3 Q 2 . py . Fill in your
Question C marks
Write your answer in the provided file AQ 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 'fruitprice' pair, as shown in the sample below:
To implement this application, you need to define a few functions:
Write a function readdata with the filename as the input parameter and return a list of strings holding all contents of this file.
Write a function listtodict with aList as input parameter and return a dictionary. Below is test case for this function:
listTest Fruit
'Fruit
'Fruit
dictTestlisttodictlistTest
printdictTest
Fruit : 'Fruit : 'Fruit :
Write a function custspend 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:
ftestcustspenddictTest
How many grams of the fruit 'Fruit price:
How many grams of the fruit 'Fruit price:
How many grams of the fruit 'Fruit price:
printftest
Write a function main as the main loop of this application. Inside the main function, do the following:
a Load the fruitprice information by opening the given text file "productsList.txt and reading the contents into a variable lsallPrices as a list.
b Convert this list to a dictionary dictProductPrice 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 custspend 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 decimal places.
The program output should adhere to the Sample Output provided below:
Sample Output :
Completed by student Chan Siu Ming with student ID
Please enter your customer ID type 'end' to exit:
Hi Please enter the weightin grams for each fruit:
How many grams of the fruit 'Apple'price:
How many grams of the fruit 'Banana'price:
How many grams of the fruit 'Grape'price:
Thank you, You have spent $ in this order.
Please enter your customer ID type 'end' to exit:
Hi Please enter the weightin grams for each fruit:
How many grams of the fruit 'Apple'price:
How many grams of the fruit 'Banana'price:
How many grams of the fruit 'Grape'price:
Thank you, You have spent $ in this order.
Please enter your customer ID type 'end' to exit: end
Today's orders:
Sample Output No order has been made.
Completed by student Chan Siu Ming with student ID
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 AQ py
Ensure that all mentioned variables sallPrices, todayOrder, dictProductPrice, customerID are used and assigned appropriate values.
Hint: Refer to the general guidelines to determine how to call the main function.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
