it keeps looping over and over again no matter what i put in

def getScores(totalScores, number): 
        score = input('Enter their score: ')
        while score <=0 or score >=100:
            print'You must enter a number between 0 and 100'
            score = input('Enter a number between 0 and 100:')
            for counter in range(0, number):
                totalScores = totalScores + score
        return totalScores

Recommended Answers

All 6 Replies

I realy dont get what you want but i just optimised your code. Hope it helps

def getScores(totalScores, number): 
        score = input('Enter their score: ')
        while score <=0 or score >=100:
            print'You must enter a number between 0 and 100'
            score = input('Enter a number between 0 and 100:')
        for counter in range(0, number):
            totalScores = totalScores + score
        return totalScores

Your code was just missing the indentation to exclude the for loop from the while.
The for loop could not run unless the while look kicks in.
;)

Simpler to write instead of lines 6 and 7

totalScores += number * score

What you are trying to do?

If you are using Python3.X, then input will return a string which is always greater than 100, print type(score) to see which class it belongs to.

i've gotten past that part now i get this

Traceback (most recent call last):
File "C:/Users/Family/Desktop/13.py", line 54, in <module>
main()
File "C:/Users/Family/Desktop/13.py", line 10, in main
averageScores = getAverage(totalScores, averageScores, number)
File "C:/Users/Family/Desktop/13.py", line 46, in getAverage
averageScores = totalScores / number
TypeError: unsupported operand type(s) for /: 'tuple' and 'int'


heres the code

def main():
    endProgram = 'no'
    print
    while endProgram == 'no':
        totalScores = 0
        averageScores = 0
        number = 0
        number = getNumber(number)
        totalScores = getScores(totalScores, number)
        averageScores = getAverage(totalScores, averageScores, number)
        printAverage(averageScores)

        endProgram = raw_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 = raw_input('Do you want to end program? (Enter no to process a new set of scores): ')

        

                
#this function will determine how many students took the test
def getNumber(number):
    
    number = input('Enter a number between 2 and 30: ')
    while number <=2 or number >=30:
        print'You must enter a number between 2 and 30'
        number = input('Enter a number between 2 and 30:')
        
    return number    

#this function will get the total scores
def getScores(totalScores, number):
    for counter in range(0, number):
        score = input('Enter their score: ')
    while score<=10 or score>=100:
        print'You must enter a number between 0 and 100'
        score = input('Enter a number between 0 and 100:')
    
        
        totalScores = totalScores + score
        return totalScores, number


#this function will calculate the average
def getAverage(totalScores, averageScores, number):
    averageScores = totalScores / number
    return averageScores

#this function will display the average
def printAverage(averageScores):
    print 'The average test score is', averageScores  
    
# calls main
main()

Write in plain words what you want to input and output (including example)

i dont get Mr. dmurder.....

can you help us to help you. Until now no one jnows what you want to achieve.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.