I need the following excercise completed using Python 3.2 Need to use the follow
ID: 3538404 • Letter: I
Question
I need the following excercise completed using Python 3.2
Need to use the following skills :
Functions and/or Value Returning Functions
Decision Structures: IF/Elif/Else
Loops
Modules
File input/output
String manipulation
Zip your .py files (you should have at least two or more) and upload them. Will not need to submit any text files, but would want a txt file to test.
Fat Jimmys Pizza Parlor
In attempting to obtain your double-fang Python status (license to Python at will) you have taken job in dingy establishment for terrible pay. Jimmy%u2019s Pizza is barely staying ahead of the health department by continually changing the establishment%u2019s name (Fat Rons, Fat Bobs, Fat Jorges, etc.). Due to your weakness for pizza, you cant resist the offer of a free pizza and $1.25 an hour plus tips.
Fat Jimmys pizzas come in four sizes:
1. Petite
2. Serious
3. Bloated Stoat
4. Orson wells
(From smallest to largest).
A pizza has a variety of toppings that are available in any size, but the prices vary by size and toppings. The table below provides Fat Jimmys pricing:
Toppings/Size
Petite
Serious
Bloated Stout
Orson Wells
Cheese only
5.95
7.83
13.45
21.50
Pepperoni
7.00
9.00
17.85
26.50
Pepperoni & Anchovy
6.50
8.50
17.35
26.00
Sausage&Garlic
9.00
11.00
19.05
26.50
Carnivore Special
11.00
13.45
21.50
32.45
Input/output Requirements
The requirements for this program have two parts.
1) The first part of the program requires you to process the datafile and determine what data from the file you will need. The functions to determine the line order price should be in an external module.
2) The output task requires you to write an output file similar to the one presented below, store the output file as finalout.txt An example of the output layout is provided below as well: (remember this should be located in an output file)
Output Requirements
Fat Jimmys Pizza Sales Report
********************************
Location #1: 24 $13,100.32
Location #2: 21 $8,610.71
Location #3: 32 $12,110,49
Location #4: 45 $19,300,40
Tot. Gross Sales: 122 $53,121.92
Note, these numbers are not correct; they are just for display purposes.
The layout of the data file for this assignment is provided below:
Sample --valid-- Data Line:
12345678901234567890 (this is just the position indicator)
3 1 6368 2 3 6 (this is a sample line of data, 3 is in posistion 1)
Data File Specifications
Column
Description
0
Location (1,2,3,4)
2
Shift (1,2)
4, 5, 6, 7
Ticket Number (0001 to 9999)
9
Pizza Size (1,2,3,4 smallest to largest)
11
Pizza Style (1,2,3,4,5 cheese to carnivore)
13
Number of pizzas ordered - (0 to 9)
You can verify this by running the following code:
myfile = open('finaldata.txt')
myline = myfile.readline()
for i in range(len(myline)):
print ("Position [", i, "]:", myline[i], sep='')
Toppings/Size
Petite
Serious
Bloated Stout
Orson Wells
Cheese only
5.95
7.83
13.45
21.50
Pepperoni
7.00
9.00
17.85
26.50
Pepperoni & Anchovy
6.50
8.50
17.35
26.00
Sausage&Garlic
9.00
11.00
19.05
26.50
Carnivore Special
11.00
13.45
21.50
32.45
Explanation / Answer
#input.py
#assumes input file is called finaldata.txt
#save this as "input.py"
price=[
[ 5.95,7.83,13.45,21.50 ],
[ 7.00,9.00,17.85,26.50 ],
[ 6.50,8.50,17.35,26.00 ],
[ 9.00,11.00,19.05,26.50 ],
[ 11.00,13.45,21.50,32.45 ]
]
def process(str):
s=str.split()
if(len(s)<6):
return [0,0,0]
loc=int(s[0])-1
num=int(s[5])
size=int(s[3])
style=int(s[4])
totalPrice = num*price[style-1][size-1]
return [loc,num,totalPrice]
#end of input.py
#################################################
#output.py
#make sure input.py and finaldata.txt is in the same folder as this file
#you need to run only this file as it uses input.py as an external module
#save and run as output.py
#output is saved in file finalout.txt
#importing input.py
import input
def main():
sales=[[0,0],[0,0],[0,0],[0,0]]
gross=0
gross_num=0
with open('finaldata.txt') as a_file:
for line in a_file:
ans=input.process(line)
l=ans[0] #location
n=ans[1] #number of pizzas
p=ans[2] #total price
sales[l][0]=sales[l][0]+n
sales[l][1]=sales[l][1]+p
gross=gross+p
gross_num=gross_num+n
with open('finalout.txt',mode="w") as a_file:
a_file.write("Fat Jimmys Pizza Sales Report ");
a_file.write("******************************** ");
i=1
for x in sales:
a_file.write("Location #{0:d}: {1:d} ${2:.2f} ".format(i,x[0],x[1]))
i=i+1
a_file.write("Tot. Gross Sales: {0:d} ${1:.2f} ".format(gross_num,gross))
main()
#end of output.py
#################################################
#finaldata.txt
#save the following lines in a simple file called finaldata.txt
#Put it in the same folder as input.py and output.py
#first line is same as the one in posted question
#MAKE SURE JUST COPY THE FOLLOWING LINES, NOT THESE COMMENTS
3 1 6368 2 3 6
2 2 3456 3 3 10
1 2 3456 2 1 10
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.