As promised, here is my final project in my Python programming course. I got the solution all by myself, although, feel free to make any changes you see fit, I've already turned it in.

For this assignment you are to develop a Python program based on the scenario and following the instructions:

Final Exam Instructions

Non-working programs or programs that crash receive a maximum of 25% of the total possible points. Make sure the program compiles and runs properly.

Your program should be neat and well documented. Essentially, I should be able to read through your program and figure out what you are doing. If you don’t think it is obvious, comment it. My best advice is to start early. If you wait too long, you may not be able to find me before the due date.

Fat Jimmy’s Pizza Parlor

In attempting to obtain your double-fang Python status (license to Python at will) you have taken yet another job in another dingy establishment for terrible pay. Jimmy’s is barely staying ahead of the health department by continually changing the establishment’s name (Fat Ron’s, Fat Bob’s, Fat Jorge’s, etc.). Due to your weakness, pizza, you can’t resist the offer of a free pizza and $1.25 an hour plus tips (you get a free pizza every hour too, but you’re not sure you want that perk).

Fat Jimmy’s 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 Jimmy’s 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


Anchovy 6.50 8.50 17.35 26.00


Sausage&Garlic 9.00 11.00 19.05 26.50


Carnivore 11.00 13.45 21.50 32.45

Input/output Requirements

The requirements for this program have two parts. The first part of the program requires you to process the datafile and determine what data from the file you will need. 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 Jimmy’s 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:

12345678901234567890123456789012345678901

3 1 6368 2 3 6

Col. Field Description

1 = Location (1,2,3,4)

7 = Shift (1,2)

13-16 = Ticket Number (0001 to 9999)

19 = Pizza Size (1,2,3,4 smallest to largest)

25 = Pizza Style (1,2,3,4,5 cheese to carnivore)

31 = Number of pizzas ordered - (0 to 9)

*The actual data file may have fields in slightly different column numbers. This is just an example to show the order in which the fields are entered in the data file.

Please remember to start the final early. The program is challenging, and deals with input and output files as well as some challenging logic in the program’s manipulations. Once complete, compress your code and your output text file into a folder for submission.

Here is the data file.

http://online.gtcc.edu/file.php/17712/FinalData.txt

Here is the module.

def getTotal(size, style, quantity):

    price = 0

    if (size == 1):
        if (style == 1):
            price = 5.95
        elif(style == 2):
            price = 7.00
        elif(style == 3):
            price = 6.50
        elif(style == 4):
            price = 9.00
        elif(style == 5):
            price = 11.00

    elif(size == 2):
        if (style == 1):
            price = 7.83
        elif(style == 2):
            price = 9.00
        elif(style == 3):
            price = 8.50
        elif(style == 4):
            price = 11.00
        elif(style == 5):
            price = 13.45

    elif(size == 3):
        if (style == 1):
            price = 13.45
        elif(style == 2):
            price = 17.85
        elif(style == 3):
            price = 17.35
        elif(style == 4):
            price = 19.05
        elif(style == 5):
            price = 21.50

    elif(size == 4):
        if (style == 1):
            price = 21.50
        elif(style == 2):
            price = 26.50
        elif(style == 3):
            price = 26.00
        elif(style == 4):
            price = 26.50
        elif(style == 5):
            price = 32.45

    saleprice = price * quantity
    return saleprice

And here is the SOLUTION.

import pricemodule

def calcPizza():

    Loc1Pizzas = 0
    Loc1Sales = 0.00
    Loc2Pizzas = 0
    Loc2Sales = 0.00
    Loc3Pizzas = 0
    Loc3Sales = 0.00
    Loc4Pizzas = 0
    Loc4Sales = 0.00

    in_file = open('FinalData.txt', 'r')
    out_file = open('finalout.txt', 'w')

    file_line = in_file.readline()

    while file_line != '':

        location = int(file_line[0])
        size = int(file_line[9])
        style = int(file_line[11])
        quantity = int(file_line[13])
        saleprice = pricemodule.getTotal(size, style, quantity)

        if location == 1:
                    Loc1Pizzas += quantity
                    Loc1Sales += saleprice

        if location == 2:
                    Loc2Pizzas += quantity
                    Loc2Sales += saleprice

        if location == 3:
                    Loc3Pizzas += quantity
                    Loc3Sales += saleprice

        if location == 4:
                    Loc4Pizzas += quantity
                    Loc4Sales += saleprice
                    
        totalgross = Loc1Sales + Loc2Sales + Loc3Sales + Loc4Sales

        file_line = in_file.readline()

    print("Fat Jimmy's Sales Report")
    print(' ')
    print('************************')
    print(' ')
    print('Location #1:', Loc1Pizzas, '$', format(Loc1Sales, ',.2f'))
    print(' ')
    print('Location #2:', Loc2Pizzas, '$', format(Loc2Sales, ',.2f'))
    print(' ')
    print('Location #3:', Loc3Pizzas, '$', format(Loc3Sales, ',.2f'))
    print(' ')
    print('Location #4:', Loc4Pizzas, '$', format(Loc4Sales, ',.2f'))
    print(' ')
    print('TOTAL GROSS SALES: $', format(totalgross, ',.2f'))
    print(' ')
    print('Data written to finalout.txt.')

    out_file.write("Fat Jimmy's Pizza Sales Report" + '\n')
    out_file.write(' ' + '\n')
    out_file.write("******************************" + '\n')
    out_file.write(' ' + '\n')
    out_file.write('Location #1: ' + (str(Loc1Pizzas)))
    out_file.write(' ${0: ,.2f}'.format(Loc1Sales) + '\n')
    out_file.write(' ' + '\n')
    out_file.write('Location #2: ' + (str(Loc2Pizzas)))
    out_file.write(' ${0: ,.2f}'.format(Loc2Sales) + '\n')
    out_file.write(' ' + '\n') 
    out_file.write('Location #3: ' + (str(Loc3Pizzas)))
    out_file.write(' ${0: ,.2f}'.format(Loc3Sales) + '\n')
    out_file.write(' ' + '\n')
    out_file.write('Location #4: ' + (str(Loc4Pizzas)))
    out_file.write(' ${0: ,.2f}'.format(Loc4Sales) + '\n')
    out_file.write(' ' + '\n')
    out_file.write('TOTAL GROSS SALES: ')
    out_file.write(' ${0: ,.2f}'.format(totalgross) + '\n')

    in_file.close()
    out_file.close()

calcPizza()

Which prints...

>>>
Fat Jimmy's Sales Report

************************

Location #1: 311 $ 4,822.78

Location #2: 206 $ 2,759.18

Location #3: 250 $ 4,210.83

Location #4: 207 $ 2,567.04

TOTAL GROSS SALES: $ 14,359.83

Data written to finalout.txt.
>>>

Your next job seems to be to learn about sequences like lists and tuples and replacing if..elif..elif... with dictionaries.

I used lists in my last assignment... I will do dictionaries next semester in the second half of the course.

You can use lists also to clean up the code

if (size == 1):
        ## if (style == 1):
            price_list = [0, 5.95, 7.00, 6.50, 9.00, 11.00]
            price = price_list[style]

    """     Replaces
    if (size == 1):
        if (style == 1:
            price = 5.95
        elif(style == 2):
            price = 7.00
        elif(style == 3):
            price = 6.50
        elif(style == 4):
            price = 9.00
        elif(style == 5):
            price = 11.00
    """

    ## or even 
    ## a list of lists
    ## the outer list=the size
    ## the inner list=the price
    ## for the first two sizes only
    size_price = [[],
                  [0, 5.95, 7.00, 6.50, 9.00, 11.00],
                  [0, 7.83, 9.00, 8.50, 11.00, 13.45]]

    for size in [1, 2]:
        this_list=size_price[size]
        for style in [2, 3, 5]:
            print "The price is %5.2f for size=%d, and style=%d" % \
                  (this_list[style], size, style) 

        #----------------------------------------------------------------
        # and similarly
        ## sub-list = quantity, sales price totals
        pizza_sales = [ [0, 0], [0, 0], [0, 0], [0, 0], [0, 0] ]
        pizza_sales[location][0] += quantity
        pizza_sales[location][1] += saleprice
        
        """  Replaces all of these type of statements
        if location == 1:
                    Loc1Pizzas += quantity
                    Loc1Sales += saleprice
        """

beautiful...

indeed i would have used lists but our instructor specifically asked us to use a nested if else statement in our module

thank you so much :-D

I have tried to run the same program and it keeps blowing up. Where am I going wrong. I have the same program written but I can't see errors.

I wish you would have pm'd me or something, sir, I would have gladly helped. However, I wasn't aware there were fellow students of mine on here. I would have posted the solution AFTER the deadline. I hope you turned it in on time. If you are having any problems still, then private message me or something.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.