[Tutor] Pease help
Hello I am a student trying to figure out this program. Here is my objective and program below. What am I doing wrong? I can't get this to work. Calculate the average pints of blood donated during a blood drive. The program should take in the number of pints donated during the drive, based on a seven hour drive period. The average pints donated during that period should be calculated and written to a file. Write a loop around the program to run multiple times. The data should be appended to the file to keep track of multiple days. If the user wants to print data from the file, read it in and then display it. Store the pints per hour and the average pints donated in a file called blood.txt. #the main function def main(): endProgram = 'no' print while endProgram == 'no': option = 0 print print 'Enter 1 to enter in new data and store to file' print 'Enter 2 to display data from the file' option = input('Enter now -') print # declare variables pints = [0] * 7 totalPints = 0 averagePints = 0 if option == 1: # function calls pints = getPints(pints) totalPints = getTotal(pints, totalPints) averagePints = getAverage(totalPints, averagePints) else: endProgram = raw_input('Do you want to end program? (Enter no or yes): ') while not (endProgram == 'yes' or endProgram == 'no'): print 'Please enter a yes or no' endProgram = raw_input('Do you want to end program? (Enter no or yes): ') #the getPints function def getPints(pints): counter = 0 while counter 7: pints[counter] = input('Enter pints collected: ') counter = counter + 1 return pints #the getTotal function def getTotal(pints, totalPints): counter = 0 while counter 7: totalPints = totalPints + pints[counter] counter = counter + 1 return totalPints #the getAverage function def getAverage(totalPints, averagePints): averagePints = float(totalPints) / 7 return averagePints #the writeToFile function def writeToFile(averagePints, pints): #the readFromFile function def readFromFile(averagePints, pints): # calls main main() ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Help with Python
Hello, I am student trying to fugure out why when I enter any number it says error. It's only suppose to do that if it's out the 1-10 range. Please help. Thank you. number = input('Enter a number between 1 and 10: ') while number 1 or number 10: print 'Please enter a number between 1 and 10' number = input('Enter a number between 1 and 10: ') number = input('Enter a number between 1 and 10: ') while number 1 or number 10: print 'Error' number = input('Enter a number between 1 and 10: ') endProgram = raw_input('Do you want to end program? (Enter no or yes): ') while not (endProgram == 'yes' or endProgram == 'no'): print 'Please enter a yes or no' endProgram = raw_input('Do you want to end program? (Enter no to process a new set of scores): ') ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Help with Python
Hello, I am a student trying to figure out Python. I am getting errors that I don't know how to fix. What do you do after you get the error message and something is highlighted? Does that have to be deleted? Anyway, here is what I mean... # The Dice Game #add libraries needed import random #the main function def main(): print #initialize variables playerOne = 'No Name' playerTwo = 'No Name' #call to inputNames playerOne, playerTwo = inputNames(playerOne, playerTwo) #while loop to run program again while endProgram == 'no': #initialize variables winnersName = 'NO NAME' p1number = 0 p2number = 0 #call to rollDice winnerName = rollDice(p1number, p2number, playerOne, playerTwo, winnerName) #call to displayInfo winnerName endProgram = raw_input('Do you want to end program? (Enter yes or no): ') #this function gets the players names def inputNames(playerOne, playerTwo): playerOne = raw_input(Enter Name) playerTwo = raw_input(Enter Name) return playerOne, playerTwo #this function will get the random values def rollDice(p1numer, p2numer, playerOne, playerTwo, winnerName): p1number = random.randint(1, 6) p1number = random.randint(1, 6) #this function displays the winner if p1number == p2number: winnerName = TIE elif p1number p2number: winnerName = playerOne else: winnerName = playerTwo return winnerName # calls main main() ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor