-3

I have researched this subject, and cannot find a relevant answer, here's my code:

#Imports#
import random
from operator import add, sub, mul
import time
from random import choice

#Random Numbers#
beg1 = random.randint(1, 10)
beg2 = random.randint(1, 10)

#Variables + Welcoming message#
correct = 0
questions = 10
print ("Welcome to the Primary School Maths quiz!!")
print ("All you have to do is answer the questions as they come up!")
time.sleep(1)

#Name#
print("Enter your first name")
Fname = input("")
print ("Is this your name?" ,Fname)
awnser = input("")
if awnser == ("yes"):
    print ("Good let's begin!")
    questions()
if input == ("no"):
    print("Enter your first name")
    Fname = input("")
    print ("Good let's begin!")




#Question Code#
def questions():
    for i in range(questions):
    ChoiceOp = random.randint (0,2)
    if ChoiceOp == "0":
        print (("What is " +beg1 ,op ,beg2)) 
        begAns = input("")
        if int(begAns) == beg1*beg2:
            print("That's right -- well done.\n")
            correct = correct +1
        else:
            print("No, I'm afraid the answer is ",begAns)

    if ChoiceOp == "1":
        print (("What is " +beg1 ,op ,beg2)) 
        begAns = input("")
        if int(begAns) == beg1-beg2:
            print("That's right -- well done.\n")
            correct = correct +1
        else:
            print("No, I'm afraid the answer is ",begAns)

    if ChoiceOp == "2":
        print (("What is " +beg1 ,op ,beg2)) 
        begAns = input("")
        if int(begAns) == beg1+beg2:
            print("That's right -- well done.\n")
            correct = correct +1
        else:
            print("No, I'm afraid the answer is ",begAns)
questions()

If I'm perfectly honest I'm not quite sure what's wrong, I have had many problems with this code that this wonderful site has helped me with, but anyway this code is designed to ask 10 random addition, subtraction and multiplication questions for primary school children any help I am thankful in advance! :D

tobias_k
  • 81,265
  • 12
  • 120
  • 179
  • 2
    What language is that? – Stephen C Jan 28 '15 at 09:39
  • "I have researched this subject, and cannot find a relevant answer" - then you should work on your research skills. Simply look at the list of related questions in the sidebar to the right. You should have found those via a google search of your question title. TL;DR: the problem is that you're having an `int` variable in your code that you try to call like a function; e.g `i = 1; i()` leads to the exact same error. – l4mpi Jan 28 '15 at 09:57

1 Answers1

0

You have both a function def questions() and a variable questions = 10. This does not work in Python; each name can only refer to one thing: A variable, a function, a class, but not one of each, as it would be possible, e.g. in Java.

To fix the problem, rename either your variable to, e.g., num_questions = 10, or your function to, e.g., def ask_question()

Also note that you call your questions function before it is actually defined. Again, this works in some other languages, but not in Python. Put your def quesitons to the top and the input prompt below, or in another function, e.g. def main().

tobias_k
  • 81,265
  • 12
  • 120
  • 179
  • tobias_k the code still comes up with the same error despite the cahnges but thanks anyway! :D – khepigamin Jan 28 '15 at 10:11
  • @khepigamin Well, what _did_ you change? Also, there are a few more errors in your code, but I can't fix all of those for you, e.g. you are also comparing integers to strings, and you forgot to define the `op` and `correct` variable. – tobias_k Jan 28 '15 at 10:16