Sunteți pe pagina 1din 5

Susan M Stuedli

CITP 110 Class Period: 1:10 pm to 3:00 pm


Instructor James McAvoy
September 25, 2015

HOMEWORK ASSIGNMENT 5
SALESPERS FIRST SALE
ONS
AMOUNT
NAME

NUMBE
R

OF

Jose

$8,500.00

SALES
3

Sally
Bill

$15,500.00
$6,000.00

1
3

$-100.00

$3,000.00
$1,000.00

2
1

Rachael

REMAINING SALES

$14,499.00
$1.00
$11,550.00
$25,000.00
$25,001.00
$0.00

$9,575.00

AVERAGE
SALE

HIGHEST SALE

LOWEST SALE

$7,666.67

$14,499.00

$1.00

$15,500.00
$14,183.33

$15,500.00
$25,000.00

$15,500.00
$6,000.00

Error: the
sale cannot
be less than
0 or greater
than 25000.
Please enter
a correct
sale
amount:
$6,287.50
$1,000.00

Error: the
sale cannot
be less than
0 or greater
than 25000.
Please enter
a correct sale
amount:

Error: the
sale cannot
be less than
0 or greater
than 25000.
Please enter
a correct sale
amount:
$3,000.00
$9,575.00
$1,000.00
$1,000.00

#
#
#
#
#
#
#

Program:
Average Sale Calculator
Programmer: Susan M Stuedli
Date:
September 24, 2015
Abstract:
This program will input a salesperson's name followed by the
first sale amount and then the number of sales as indicated
below for a used car dealership. The program will then display
the salesperson's average, highest, and lowest sale.

# Define the main function


def main():
# Create a variable to control the loop.
keep_going = 'y'
# Create a counter for salespersons.
number_of_salespersons = 0
# Process each salesperson's sales.
while keep_going == 'y' or keep_going == 'Y':
# Use a function to process each salesperson.
process_salesperson()
number_of_salespersons += 1
# Are there more salespersons?
keep_going = input('Are there more salespersons? (enter y for yes): ')
# Display the total number of salespersons.
print('There were', number_of_salespersons, 'salespersons processed.')
# Process each salesperson's sale.
def process_salesperson():
# Get the salesperson's name.
name = input("What is the salesperson's name? ")

print('Enter', name + "'s amount for first sale: ")


first_sale = float(input())
# Validate the sale is > 0 and < 25000.
while first_sale < 0 or first_sale > 25000:
print("Error: the sale cannot be less than 0 or greater than 25000.")
first_sale = float(input("Please enter a correct sale amount: "))
# Initialize total, lowest, and highest sale to first sale.
total_sales = first_sale
lowest_sale = first_sale
highest_sale = first_sale
# Get the number of sales for this salesperson.
print('How many sales does', name, 'have?')
number_of_sales = int(input())
for number in range(2, number_of_sales + 1):
# Get the sale amount.
print('Enter', name + "'s sale #" + str(number) + ':'),
sale = float(input())
# Validate the sale is > 0 and < 25000.
while sale < 0 or sale > 25000:
print('ERROR: the sale cannot be less than 0 or greater than \
25000.')
sale = float(input("Please enter a correct sale amount: "))
# Accumulate the sales.
total_sales += sale
# Check for highest sale.
if sale > highest_sale:
highest_sale = sale

# Check for lowest sale.


elif sale < lowest_sale:
lowest_sale = sale
# Compute average sale.
average_sale = float(total_sales) / number_of_sales
# Display the average, highest, and lowest sale.
print('')
print(name + "'s average sale was: $", format(average_sale, ".2f"), \
sep='')
print(name + "'s highest sale was: $", format(highest_sale, ".2f"), \
sep='')
print(name + "'s lowest sale was: $", format(lowest_sale, ".2f"), \
sep='')
print('')
# Call the main function.
main()

S-ar putea să vă placă și