0
import random
import time
counter=0
score=0
count=0

function=['+','x','÷','-']

print('Welcome To The Arithmetic Quiz!')
name=input('Please enter you name..')
print('Thanks' , name , 'Lets Get Started!')

while counter <10:
    firstnumber=random.randint(0,12)
    secondnumber=random.randint(0,6)
    function=random.choice(function)

question=print(firstnumber, function, secondnumber, '=')
input('Answer:')
counter= counter+1

if function== '+':
                count==firstnumber+secondnumber
                if count == int (answer):
                    print ('Correct!')
                    score= score+1
                else:
                    print ('Incorrect')
elif function== 'x':
                count==firstnumber*secondnumber
                if count == int (answer):
                    print ('Correct!')
                    score= score+1
                else:
                    print ('Incorrect')
elif function== '-':
                count==firstnumber-secondnumber
                if count == int (answer):
                    print ('Correct!')
                    score= score+1
                else:
                    print ('Incorrect')
elif function== '÷':
                count==firstnumber/secondnumber
                if count == int (answer):
                    print ('Correct!')
                    score= score+1
                else:
                    print ('Incorrect')

Could anybody correct the end section ( if function ) and ( elif function ) I think it is something to do with the variable names.

It also does not run properly as it stops at: print('Thanks' , name , 'Lets Get Started!'), again I am unsure why this is.

HavelTheGreat
  • 3,299
  • 2
  • 15
  • 34
  • For some [reading material](http://stackoverflow.com/questions/26260950/how-can-i-randomly-choose-a-maths-operator-and-ask-recurring-maths-questions-wit/26261125#26261125) – Cory Kramer Feb 25 '15 at 20:57

2 Answers2

0

Your counter isn't incrementing within your while loop, as you have some serious indentation problems. As a result, your while loop just runs forever and you have an infinite loop. Make sure you indent the code including the counter which you wish to have in your while loop in order for that code to be executed and for your while loop to actually stop.

EDIT: I fixed your indentation and your counter. Note that your division still will not work unless the quotient happens to be an integer, if you want to fix that you'll have to do some research yourself.

import random
import time
counter=0
score=0
count=0

function=['+','x','÷','-']

print('Welcome To The Arithmetic Quiz!')
name=input('Please enter you name.')
print('Thanks' , name , 'Lets Get Started!')

while counter <10:
    firstnumber=random.randint(0,12)
    secondnumber=random.randint(0,6)
    operator=random.choice(function)

    question=print(firstnumber, operator, secondnumber, '=')
    userAnswer = input('Answer:')


    if operator== '+':
                    count=firstnumber+secondnumber
                    if count == int (userAnswer):
                        print ('Correct!')
                        score= score+1
                    else:
                        print ('Incorrect')
    elif operator== 'x':
                    count=firstnumber*secondnumber
                    if count == int (userAnswer):
                        print ('Correct!')
                        score= score+1
                    else:
                        print ('Incorrect')
    elif operator== '-':
                    count=firstnumber-secondnumber
                    if count == int (userAnswer):
                        print ('Correct!')
                        score= score+1
                    else:
                        print ('Incorrect')
    elif operator== '÷':
                    count=firstnumber/secondnumber
                    if count == int (userAnswer):
                        print ('Correct!')
                        score= score+1
                    else:
                        print ('Incorrect')
    counter += 1

print ("Your quiz is over!")
HavelTheGreat
  • 3,299
  • 2
  • 15
  • 34
  • It would be, but it would hardly be helpful. I would take a look at the reading material that was provided in the comments by Cyber, and try to figure it out yourself. Follow my answer, try and diagnose any further issues you have, and if you absolutely cannot figure them out then update your question or ask another question! – HavelTheGreat Feb 25 '15 at 21:10
  • I have attempted the changes you suggest but still no luck. Still a problem with the indentations I think. Would it be possible to see how you would have corrected it, it would be appreciated –  Feb 25 '15 at 21:51
  • @123abc I fixed your indentation and your counter and `if` assignments. If you have any further questions it is probably best to specify them in a new question (if they are valid questions). An accepted answer is always appreciated. – HavelTheGreat Feb 25 '15 at 22:01
  • @123abc You can close a question with the checkmark beside a suitable answer. – HavelTheGreat Feb 25 '15 at 22:11
0

Your code is poorly indented, as Elizion has pointed out. Also count==number + number should be count=number + number. Then function is assigned a value which can never be changed - consider changing one of the variable names. Use else, not elif for the final possible condition. How about printing the score at the end. I've corrected your code, but have a go yourself first...

HavelTheGreat
  • 3,299
  • 2
  • 15
  • 34
BendyMan
  • 301
  • 1
  • 3
  • 8