
Renee P.
asked 08/19/21Please help I’m so lost
1. Creates a functioninputNumbersthat uses a loop to allow the user to input 5 numbers between 1 and 10 and store them in an array called numArray. All input should be validated as a number between 1-10 inclusive. Call the function from def main().
2. Creates a function addNumsthat accepts numArrayand uses a loop to add the numbers in the array. Call the function from def main(). Return the total to def main()and assign the total to a variable total. Display total.
3. Creates a function writeArraythat writes contents of the array to a file called dat, one number per line. A new file should be created if a file calledExam2.datcurrently exists. Call the function from def main()
4. Creates a function readArraythat reads contents of the file and displays them.
5. Displays how many of the numbers read are greater than 5 and how many of the numbers are 5 or less.
6. Implements the following pseudocode for the main module exactly as shown.
Main module
//Call functions to input numbers.
Set numArray = inputNumbers()
//Call function to add numbers
Set total = addNums(numArray)
Display “The total of the numbers is”, total
// Write array contents to a file.
Call writeArray(numArray)
//Read and display numbers in the file
Call readArray()
End Module
1 Expert Answer

Patrick B. answered 08/19/21
Math and computer tutor/teacher
def inputNumbers():
numArray = []
for i in range(5):
x=-1
while (int(x)<1) or (int(x)>10):
x = input("Please Input # between 1 and 10 :>")
numArray.append(x)
return(numArray)
###########################################################
def addNums(numArray):
sum=0
for i in range(5):
sum = int(sum) + int(numArray[i])
return(sum)
#####################################################
def writeArray(numArray,filename):
f = open(filename, "w")
f.writeLines(numArray)
f.close()
################################################
def statsArray(numArray):
countLessThan5 = 0
countGreaterThan5=0
countEqual5=0
for i in range(5):
if int(numArray[i])>5:
countGreaterThan5 = int(countGreaterThan5)+1
if int(numArray[i])<5:
countLessThan5 = int(countLessThan5)+1
if int(numArray[i])==5:
countEqual5 = int(countEqual5)+1
print(" # greater than 5: " + str(countGreaterThan5))
print(" # less than 5: " + str(countLessThan5))
print(" # equal to 5: " + str(countEqual5))
#####################################################
numArray = inputNumbers()
print(numArray)
sum = addNums(numArray)
print("The sum is " + str(sum))
statsArray(numArray)
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Patrick B.
using online compiler, so file IO does not work.08/19/21