The assignment I am struggling with due to lack of time.
Create a program that reads data from and builds parallel arrays for the plant items, with each array containing the plant's full name, zone, light, and price, respectively. Availability will be ignored. After reading the data and building the arrays, display the plant items similar to the following:
common name (botanical name) - zone - light - price
At the bottom, display the total number of items in the catalog and the average price per item similar to:
0 items - $0.00 average price
Need it to look like this?
If you choose string functions, you already know everything you need. Just create your ownfunctions to find tags using string.find() and string[slice].
If you chooseRegExfunctions, you need to learn how to useRegEx.RegExmay be easier, but you have to first learn and understandRegEx. be helpful.
If you choose XML functions, you need to learn how to use XML. XML may be theeasiest, but you first have to learn and understand XML functions. be helpful.
A few examples that I have created that are similar and would only be accepted.
# This program will ask the user how many scores they would like to enter. It will then use a loop to calculate the high,low, and average score.
def get_count():
print("Enter the number of scores you want to average.")
count = int(input())
return count
def load_array(count):
scores = [0] * count
for index in range(0, count, 1):
print("Enter the scores.")
scores[index] = int(input())
return scores
def calculate_average(scores):
sum = 0
for index in range(0, len(scores)):
sum += scores[index]
average = sum / len(scores)
return average
def calculate_highest(scores):
highest = scores[0]
for index in range(0, len(scores), 1):
if scores[index] > highest:
highest = scores[index]
return highest
def calculate_lowest(scores):
lowest = scores[0]
for index in range(0, len(scores), 1):
if scores[index] < lowest:
lowest = scores[index]
return lowest
def display_results(high, low, average):
print("The largest score is ....." + str(high))
print("The lowest score is ....." + str(low))
print("The average score is ...." + str(average))
def main():
count = get_count()
scores = load_array(count)
highestscore = calculate_highest(scores)
lowestscore = calculate_lowest(scores)
averagescore = calculate_average(scores)
display_results(highestscore, lowestscore, averagescore)
main()
Another example.
# A program that asks the user for a year, and then calculate whether or not the given year is a leap year.
def get_leapyear():
print("Enter the year you where born?")
leapyear = int(input())
return leapyear
def get_year():
year = int(input())
return year
def get_month():
month = int(input())
return month
def is_leap_year(leapyear):
return (leapyear % 4 == 0) and (leapyear % 100 != 0) or (leapyear % 400 == 0)
def days_in_month(month, year,is_leap_year):
month = int(input())
year = int(input())
if month in ['September', 'April', 'June', 'November']:
30
elif month in ['January', 'March', 'May', 'July', 'August', 'October', 'December']:
31
elif month == 'February' and is_leap_year(year) == True:
29
elif month == 'February' and is_leap_year(year) == False:
28
else:
return None
def main():
leapyear = get_leapyear()
is_leap_year(leapyear)
days_in_month(month,year)
year = get_year()
month = get_month()
main()
efgetscores():
print("Enter how many scores you want me to calculate.")
scores = int(input())
return scores
def getscore():
print("Enter the score.")
scores = int(input())
return scores
def calculateaverage(scores, total):
average = total / scores
return average
def forloop(scores):
total = 0
for i in range(0, scores, 1):
score = getscore()
total = total + score
average = total / scores
return average
def whileloop(scores):
total = 0
i = 0
while i < scores:
score = getscore()
total = total + score
i = i + 1
average = total / scores
return average
def displayresult(average):
print("Your average is " + str(average))
def main():
scores = getscores()
average = forloop(scores)
displayresult(average)
average = whileloop(scores)
displayresult(average)
main()