jeudi 20 août 2015

Python "def" Issue [on hold]

sorry for my last fail question but this time I was wondering how I could randomly select a function. Eg. Addition, Subtraction, etc... I basically want to be able to randomly be asked any question from the functions set up. Here is code:

    #Maths Helper Program
import random
def Welcome():
    print ("Welcome to Rory's Maths Assistance Program!")
    print ("You may select test(T) mode or pratise(P) mode to begin")
    x = input ("Please enter your selection T/P : ")
    if x == "T":
        Test()
    elif x == "P":
        Practise()
    else :
        print("Your choice was not an option...")
        print("")
        Welcome()

def Difficulity():
    print ("Please select either Easy(E), Medium(M), or Hard(H) difficulty to begin")


def Addition ():
    a = random.randint(0,20)
    b = random.randint(0,20)
    d = a + b
    c = input("What is " + str(a) + "+" + str(b) + "?    ")
    if int(c) == int(d):
        print ("Correct!")
    elif c != d:
        print ("Incorrect, the correct answer was " + str(d) )

def Subtraction ():
    a = random.randint(0,20)
    b = random.randint(0,20)
    d = a - b
    c = input("What is " + str(a) + "-" + str(b) + "?    ")
    if int(c) == int(d):
        print ("Correct!")
    elif c != d:
        print ("Incorrect, the correct answer was " + str(d) )

def Multiplication ():
    a = random.randint(0,10)
    b = random.randint(0,10)
    d = a * b
    c = input("What is " + str(a) + "x" + str(b) + "?    ")
    if int(c) == int(d):
        print ("Correct!")
    elif c != d:
        print ("Incorrect, the correct answer was " + str(d) )

def Division ():
    a = random.randint(0,10)
    b = random.randint(0,10)
    d = a * b
    c = input("What is " + str(d) + "÷" + str(a) + "?    ")
    if int(c) == int(b):
        print ("Correct!")
    elif c != b:
        print ("Incorrect, the correct answer was " + str(b) )

def Practise ():
    a = int(input("How many questions would you like?    "))
    while a <= 0:



Welcome()




Aucun commentaire:

Enregistrer un commentaire