Create a dictionary (order_dict) that the key is the burger number, and the value is a list of the quantities. For example: order_dict which is {'1': [10, 3, 78], '2': [35, 0, 65], '3': [9, 23, 0], '4': [0, 19, 43], '5': [43, 0, 21]} Create a dictionary (total_order_dict) that the key is the burger number, and the value is the total of the quantities for that burger. For example: total_order_dict which is {'1': 91, '2': 100, '3': 32, '4': 62, '5': 64} Use "assert to test the values of the total_order_dict For example: expected_result_ototal_order_dict = {'1': 91, '2': 100, '3': 32, '4': 62, '5': 64} assert actual_result_ototal_order_dict['1'] == expected_result_ototal_order_dict['1'] , "The actual result is not the \ same as expected result for the order number 1!" (and test the other elements) The function can be like: def test_sum(): #Testing assert actual_result_ototal_order_dict['1'] == 91, "The actual result is not the \ same as expected result for the order number 1!" Write this dictionary in a csv file which the first is the key (number of the burger ) and the next number after comma is the value ( the total of the quantities for that burger) you can use like this: def write_order_csv(actual_result_ototal_order_dict,outputFile): with open(outputFile, 'w') as outfile: for key in actual_result_ototal_order_dict.keys(): outfile.write("%s,%s\n"%(key,actual_result_ototal_order_dict[key])) #or writer = csv.writer(outfile) writer.writerow(key + actual_result_ototal_order_dict[key]) You main function can be like: if __name__ == "__main__": actual_result_ototal_order_dict = read_order("order.csv") test_sum() print("Everything passed") write_order_csv(actual_result_ototal_order_dict,"outputfile.csv") My code is import csv order_dict = {'1': [10, 3, 78], '2': [35, 0, 65], '3': [9, 23, 0], '4': [0, 19, 43], '5': [43, 0, 21]} total_order_dict = {} def read_file(): with open ("order.csv",'r') as file: reader = csv.reader(file) for key, values in order_dict.items(): order_dict[key] = sum(values) print(key,sum(values)) total_order_dict = order_dict return total_order_dict def testing_value(): assert total_order_dict["2"] == 100, "The total results is not equal with order_dict" def write_file(read_file): with open ("order.csv",'w') as file: for key in total_order_dict(): read_file. write(key,",",values) if __name__ == "__main__": read_file() testing_value() write_file(read_file) please modify my code to be the same as the output
- Create a dictionary (order_dict) that the key is the burger number, and the value is a list of the quantities.
For example: order_dict which is {'1': [10, 3, 78], '2': [35, 0, 65], '3': [9, 23, 0], '4': [0, 19, 43], '5': [43, 0, 21]}
- Create a dictionary (total_order_dict) that the key is the burger number, and the value is the total of the quantities for that burger.
For example: total_order_dict which is {'1': 91, '2': 100, '3': 32, '4': 62, '5': 64}
- Use "assert to test the values of the total_order_dict
For example:
expected_result_ototal_order_dict = {'1': 91, '2': 100, '3': 32, '4': 62, '5': 64}
assert actual_result_ototal_order_dict['1'] == expected_result_ototal_order_dict['1'] , "The actual result is not the \
same as expected result for the order number 1!"
(and test the other elements)
The function can be like:
def test_sum():
#Testing
assert actual_result_ototal_order_dict['1'] == 91, "The actual result is not the \
same as expected result for the order number 1!"
- Write this dictionary in a csv file which the first is the key (number of the burger ) and the next number after comma is the value ( the total of the quantities for that burger)
you can use like this:
def write_order_csv(actual_result_ototal_order_dict,outputFile):
with open(outputFile, 'w') as outfile:
for key in actual_result_ototal_order_dict.keys():
outfile.write("%s,%s\n"%(key,actual_result_ototal_order_dict[key]))
#or
writer = csv.writer(outfile)
writer.writerow(key + actual_result_ototal_order_dict[key])
You main function can be like:
if __name__ == "__main__":
actual_result_ototal_order_dict = read_order("order.csv")
test_sum()
print("Everything passed")
write_order_csv(actual_result_ototal_order_dict,"outputfile.csv")
My code is
import csv
order_dict = {'1': [10, 3, 78], '2': [35, 0, 65], '3': [9, 23, 0], '4': [0, 19, 43], '5': [43, 0, 21]}
total_order_dict = {}
def read_file():
with open ("order.csv",'r') as file:
reader = csv.reader(file)
for key, values in order_dict.items():
order_dict[key] = sum(values)
print(key,sum(values))
total_order_dict = order_dict
return total_order_dict
def testing_value():
assert total_order_dict["2"] == 100, "The total results is not equal with order_dict"
def write_file(read_file):
with open ("order.csv",'w') as file:
for key in total_order_dict():
read_file. write(key,",",values)
if __name__ == "__main__":
read_file()
testing_value()
write_file(read_file)
please modify my code to be the same as the output
![order.csv-5
1,10,3,78
2,35,0,65
3,9,23,0
4,0,19,43
5,43,0,21](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F5483afab-7850-40f6-959f-e698dea1419a%2F87a3e839-c413-4ff1-8609-afd80e49f17e%2F14zktja_processed.png&w=3840&q=75)
![outputfile.csv-
1,91
2,100
3,32
4,62
5,64](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F5483afab-7850-40f6-959f-e698dea1419a%2F87a3e839-c413-4ff1-8609-afd80e49f17e%2Fvaa7nkp_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps with 3 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)