Files
2022-10-12 20:18:32 -04:00

95 lines
3.7 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# %%
# File: Pease-hw3a.py
# Author: PEASE, NICHOLAS
# Date: 12 OCT 2022
# Section: 1002-LAB
# E-mail: nicholas.pease@maine.edu
# Description:
# Write a program to ask the user annual number of visitors at their five
# favorite Maine parks and then print out some descriptive statistics of those figures.
# The descriptive statistics should include the minimum attendance at any park, the
# maximum attendance at any park, the total attendance, and the average attendance at
# all the parks. The report on the minimum and maximum should include the name of
# the park.
# You should write functions for each of the descriptive statistics, specifically
# attendMin(), attendMax(), attendTotal(), and attendAvg(). Each function should take
# the attendance at the five parks as input and return the value computed.
# The most natural way to store the park data is in a list. Since you know the number of
# entries and the identities of each, you should be able to do this with your current
# understanding of lists. Specifically, you can create lists of five elements one
# element for each park. You do not need the more flexible capabilities to alter lists that
# we will discuss later.
# Collaboration:
# I collaborated with no one
# %%
def main():
parks = ['Camden Hills','Acadia','Quoddy Head','Baxter','Moose Point']
park_attendance = [0]*len(parks)
for i in range(0,len(parks)):
user_input = input("What is one of your favorite Maine parks? ")
park_attendance_input = int(input("How many thousand people visit "+user_input+" in a year? "))
for n in range(0,len(park_attendance)):
if parks[n].lower() == user_input.lower():
park_attendance[n] = park_attendance_input
fewest_park_index, fewest_number = attendMin(park_attendance)
most_park_index, most_number = attendMax(park_attendance)
total_visitors = attendTotal(park_attendance)
average_visitors = attendAvg(park_attendance)
print("The park with the fewest visitors is "+parks[fewest_park_index]+" with "+addCommas(fewest_number)+" thousand.")
print("The park with the most visitors is "+parks[most_park_index]+" with "+addCommas(most_number)+" thousand.")
print("The total number of visitors at those parks is "+addCommas(total_visitors)+" thousand.")
print("The average number of visitors per park is "+addCommas(average_visitors)+" thousand.")
# %%
# I am aware there are better ways to do this, but I am only using methods I have been taught.
def addCommas(input):
input = str(input)
numbers_used = 0
output = 0
if len(input)>3:
for i in range(len(input)-3,0,-3):
if output:
output = input[i:i+3] + "," + output
else:
output = input[i:i+3]
numbers_used+=1
output = input[0:len(input)-numbers_used*3]+","+output
else:
output = input
return output
# %%
def attendMin(park_attendance):
minimum = park_attendance[0]
park_index = 0
for i in range(1,len(park_attendance)):
if park_attendance[i] < minimum:
minimum = park_attendance[i]
park_index = i
return park_index, minimum
# %%
def attendMax(park_attendance):
maximum = park_attendance[0]
park_index = 0
for i in range(1,len(park_attendance)):
if park_attendance[i] > maximum:
maximum = park_attendance[i]
park_index = i
return park_index, maximum
# %%
def attendTotal(park_attendance):
total = 0
for i in range(0,len(park_attendance)):
total+=park_attendance[i]
return total
# %%
def attendAvg(park_attendance):
total = attendTotal(park_attendance)
return total // len(park_attendance)
main()