Ok heres the deal they're both a mathematics program but i want to make it like this...
from Tkinter import *
import tkMessageBox
import random
def ask():
global num1
num1 = random.randint(1, 100)
global num2
num2 = random.randint(1, 100)
global answer
answer = num1 + num2
label1.config(text='What is ' + str(num1) + '+' + str(num2) + '?')
# put the cursor into the Enter-Box
entry1.focus_set()
def checkAnswer():
mainAnswer = entry1.get()
# if empty give message
if len(mainAnswer) == 0:
tkMessageBox.showwarning(message='Need to enter some numbers!')
return
if int(mainAnswer) != answer:
tkMessageBox.showwarning(message='The correct answer is: ' + str(answer))
else:
tkMessageBox.showinfo(message='Correct! :)')
#set the window
root = Tk()
root.title("Mikey's Multiplication Quiz")
root.geometry('500x500')
# welcome message
label2 = Label(root, text="Hi!\n Let's do some Mathematics problems!")
label2.config(font=('times', 18, 'bold'), fg='black', bg='white')
label2.grid(row=0, column=0)
#add label
label1 = Label(root)
label1.grid(row=2, column=0)
#entry
entry1 = Entry(root)
entry1.grid(row=3, column=0)
# bind the return key
entry1.bind('<Return>', func=lambda e:checkAnswer())
#button
askBtn = Button(root, text='Ask Me a Question!', command=ask)
askBtn.grid(row=4, column=0)
okButton = Button(root, text='OK', command=checkAnswer)
okButton.grid(row=4, column=1)
root.mainloop()
and from this code below implement it to like the one above ^^^^
name = raw_input("\t\t\tPlease Enter Your Name: ")
print
print "\t\t\t\tHello", name
print "\t\t\tWelcome to my Mathematics Game"
# Selecting the operation of Addition and Substraction followed by the difficulty
print
operation = str(raw_input("\t\t\tAddition (A) or Substraction (S)"))
if operation == "A" or operation == "a":
my_op = 'Add'
difficulty = str(raw_input("\tSelect a difficulty - Easy (E)(1-100), Medium (M) (1-200) or Hard (H) (1-500)"))
print
print "Addition"
print '** ** **'
print
elif operation == "S" or operation == "s":
my_op = 'Sub'
difficulty = str(raw_input("\tSelect a difficulty - Easy (E)(1-100), Medium (M) (1-200) or Hard (H) (1-500)"))
print
print "Subtraction"
print '** ** ** **'
print
if difficulty == "Easy" or difficulty == "easy" or difficulty == "E" or difficulty == "e":
my_rand_range = 100
elif difficulty == "Medium" or difficulty == "medium" or difficulty == "M" or difficulty == "m":
my_rand_range = 200
elif difficulty == "Hard" or difficulty == "hard" or difficulty == "H" or difficulty == "h":
my_rand_range = 500
# Amount of questions asked (10) and randomisation of numbers
import random
counter = 0
while counter < 10:
counter = counter +1
# Difficulty - Easy, Medium or Hard
number1 = random.randrange( my_rand_range ) + 1
number2 = random.randrange( my_rand_range ) + 1
# Addition Calculations
if my_op == 'Add':
print number1, "+", number2, "="
# Substraction Calculations
elif my_op == 'Sub':
print number1, "-", number2, "="
# Input for answer
answer = int(raw_input("Type in your answer: "))
# If Its "Correct" or "Incorrect"
if ( answer == number1 + number2 and my_op == 'Add' ) or \
( answer == number1 - number2 and my_op == 'Sub' ):
print "Correct :)"
print
else:
print "Incorrect :("
print
raw_input("\n\nPress the enter key to exit.")
see i want code number 2 to look like code number 1 somehow
Please can anyone figure this out
thanks