Hello, I've spent hours but can't seem to figure out how. This is the question:
modify the program so that the prompts that ask the user to enter a transaction include the number of the transaction that should be entered next. Here's what the prompts should look like:

Enter quiz score 1 10
Enter quiz score 2 12
...

Note that the prompts should remain on the same line as the user's inputs (which are shown in bold above). In addition, make sure that the first quiz score has the number 1, the second quiz score has the number 2, and so on. Hint: Instead of specifying the prompt as part of the input statement, use a separate print statement that comes before the input statement, and change the input statement so that it does not take an argument, as follows:

score = input()
This is what I have so far:

numQuiz = input("Enter the number of quizzes:  ")
total = 0
for i in range(numQuiz):
    score = input("Enter a quiz score: ");
    total = total + score
print "------------------------------------"
# Compute the average and print it.
average = total / numQuiz
print "The average is", average

I'm guessing I should use another for statement, but I keep getting error.
Please help!

Edited 7 Years Ago by rociel: putting code tag

Range will start at zero if you don't tell it the start number. Try this:

for i in range(1, numQuiz):

That should work, don't forget to check the mark thread as solved once your question has been answered.

Range will start at zero if you don't tell it the start number. Try this:

for i in range(1, numQuiz):

That should work, don't forget to check the mark thread as solved once your question has been answered.

Hi, thank you for the reply.
I tried this but it didn't work...
What I'm trying to do is having the program to ask:
Enter quiz score 1:
Enter quiz score 2:
Enter quiz score 3:
and so on

thanks!

This is what the professor asked:
In the body of the for statement, you should replace the current input statement with a print statement followed by an input statement that doesn't include the prompt. Instead, the print statement will print the prompt.

I tried this

numQuiz = input("Enter the number of quizzes:  ")
total = 0
for i in range(numQuiz):
    print ('Enter a score: ')
    score= input()
    total = total + score
print "------------------------------------"
# Compute the average and print it.
average = total / numQuiz
print "The average is", average

I just don't really know how to fix this problem :((

numQuiz = input("Enter the number of quizzes:  ")
total = 0
for i in range(numQuiz):
    print ('Enter quiz score %d: ' % i) # 
    # OR
    print ('Enter quiz score ', str(i), ' : ')
    score= input()
    total = total + score
print "------------------------------------"
# Compute the average and print it.
average = total / numQuiz
print "The average is", average

Edited 7 Years Ago by jice: n/a

Hi jice, thank you for the reply.
I tried both methods, but I can't seem to force the user input and the prompt to be on the same line. And also, the prompt starts at 0 instead.

Enter the number of quizzes: 4
Enter a score 0 :
4
Enter a score 1 :
5
Enter a score 2 :
6
Enter a score 3 :
4
------------------------------------
The average is 4

I went back and put (1, NumQuiz)
but then that will give me one less number of prompt for the number of quizzes I input

Look at the buildin functions in the manual... you've got some parameters.
You just have to write :

print ('Enter quiz score %d: ' % i, end='')

My version is similar to jice's. I think that's the right way to do it:

numQuiz = input( "Enter the number of quizzes: " )
total = 0
for i in range( 1, numQuiz + 1 ):
     score = input("Enter quiz score %d: " % ( i ) )
     total += score

print "------------------------------------"

# Compute the average and print it.
average = total / numQuiz
print "The average is", average

I haven't tested it so if there are any errors let me know :D

P.s you can just remove the colon at the end of the input statement if you don't need it...

Edited 7 Years Ago by masterofpuppets: n/a

I just noticed another specification in the problem - the separate print statement. that's another way of doing it..

numQuiz = input( "Enter the number of quizzes: " )
total = 0
for i in range( 1, numQuiz + 1 ):
     # if you put the comma here the line remains the same
     print ("Enter quiz score %d:" % ( i ) ),
     score = input()
     # here the new line is automatically generated by the input function
     total += score

print "------------------------------------"

# Compute the average and print it.
average = total / numQuiz
print "The average is", average

Thanks a lot everyone,
this is the final working version!

numQuiz = input("Enter the number of quizzes:  ")
total = 0
for i in range(1,numQuiz +1):
    print 'Enter a score', str(i),': ',
    score = input()
    total = total + score
print "------------------------------------"
# Compute the average and print it.
average = float (total) / numQuiz
print "The average is", average

I'm so happy!!! :D

-marks as solved-

This question has already been answered. Start a new discussion instead.