Question: This is my code : def main(): endProgram = 'no' print() while endProgram == 'no': option = 0 print() print('Enter 1 to enter in new

This is my code :

def main():

endProgram = 'no'

print()

while endProgram == 'no':

option = 0

print()

print('Enter 1 to enter in new data')

print('Enter 2 to display data now')

print('Enter 3 to store data in file')

print('Enter 4 to display data from file')

option = int(input('Enter now -->'))

notGreenCost = [0] * 12

goneGreenCost = [0] * 12

savings = [0] * 12

month = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']

if option == 1:

notGreenCost = getNotGreen(month, notGreenCost)

goneGreenCost = getGoneGreen(month, goneGreenCost)

savings = energySaved(savings, notGreenCost, goneGreenCost)

elif option == 2:

displayInfo(month, savings, notGreenCost, goneGreenCost)

elif option == 3:

writeToFile(month,savings)

else:

readFromFile(month, savings)

endProgram = input('Do you want to end program? (Enter yes or no): ')

while not (endProgram == 'yes' or endProgram == 'no'):

print('Please enter a yes or no')

endProgram = input('Do you want to end program? (Enter yes or no): ')

def getNotGreen(month, notGreenCost):

counter = 0

while counter < 12:

print('Enter NOT GREEN energy cost for', month[counter])

notGreenCost[counter] = int(input('Enter now -->'))

counter = counter + 1

print('------------------------------------')

return notGreenCost

def getGoneGreen(month, goneGreenCost):

counter = 0

while counter < 12:

print('Enter GONE GREEN energy costd for', month[counter])

goneGreenCost[counter] = int(input('Enter now -->'))

counter = counter + 1

print('------------------------------------')

return goneGreenCost

def energySaved(savings, notGreenCost, goneGreenCost):

counter = 0

while counter < 12:

savings[counter] = notGreenCost[counter] - goneGreenCost[counter]

counter = counter + 1

return savings

def writeToFile(month, savings):

outFile = open('savings.txt', 'a')

print('Savings', file=outFile)

print('-------', file=outFile)

counter = 0

while counter < 12:

outFile.write(month[counter] + ' ')

outFile.write(str(savings[counter]) + ' ')

counter = counter + 1

outFile.close()

def readFromFile(month, savings):

inFile = open('savings.txt', 'r')

str1 = inFile.read()

print(str1)

month = inFile.read()

savings = inFile.read()

print(month)

print(savings)

print()

inFile.close

def displayInfo(month, savings, notGreenCost, goneGreenCost):

counter = 0

print()

print('SAVINGS')

print('______________________________________________')

print('SavingsNot GreenGone GreenMonth')

print('______________________________________________')

while counter < 12:

print()

print('$',savings[counter],'$',notGreenCost[counter],'$',goneGreenCost[counter],'',month[counter])

counter = counter + 1

main()

I don't know why my output is like this:

Enter 1 to enter in new data

Enter 2 to display data now

Enter 3 to store data in file

Enter 4 to display data from file

Enter now -->1

Enter NOT GREEN energy cost for January

Enter now -->789

Enter NOT GREEN energy cost for February

Enter now -->790

Enter NOT GREEN energy cost for March

Enter now -->890

Enter NOT GREEN energy cost for April

Enter now -->773

Enter NOT GREEN energy cost for May

Enter now -->723

Enter NOT GREEN energy cost for June

Enter now -->759

Enter NOT GREEN energy cost for July

Enter now -->690

Enter NOT GREEN energy cost for August

Enter now -->681

Enter NOT GREEN energy cost for September

Enter now -->782

Enter NOT GREEN energy cost for October

Enter now -->791

Enter NOT GREEN energy cost for November

Enter now -->898

Enter NOT GREEN energy cost for December

Enter now -->923

------------------------------------

Enter GONE GREEN energy costd for January

Enter now -->546

Enter GONE GREEN energy costd for February

Enter now -->536

Enter GONE GREEN energy costd for March

Enter now -->519

Enter GONE GREEN energy costd for April

Enter now -->493

Enter GONE GREEN energy costd for May

Enter now -->472

Enter GONE GREEN energy costd for June

Enter now -->432

Enter GONE GREEN energy costd for July

Enter now -->347

Enter GONE GREEN energy costd for August

Enter now -->318

Enter GONE GREEN energy costd for September

Enter now -->453

Enter GONE GREEN energy costd for October

Enter now -->489

Enter GONE GREEN energy costd for November

Enter now -->439

Enter GONE GREEN energy costd for December

Enter now -->516

------------------------------------

Do you want to end program? (Enter yes or no): no

Enter 1 to enter in new data

Enter 2 to display data now

Enter 3 to store data in file

Enter 4 to display data from file

Enter now -->3

Do you want to end program? (Enter yes or no): no

Enter 1 to enter in new data

Enter 2 to display data now

Enter 3 to store data in file

Enter 4 to display data from file

Enter now -->4

Savings

-------

January

0

February

0

March

0

April

0

May

0

June

0

July

0

August

0

September

0

October

0

November

0

December

0

Do you want to end program? (Enter yes or no): yes

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!