Question

Python 3+ (using TKinter): 1.) Develop new TKinter GUI widget class Ed that can be used to teach first-graders addition and subtraction. The GUI should contain two Entry widgets and a Button widget la...

Python 3+ (using TKinter):

1.) Develop new TKinter GUI widget class Ed that can be used to teach first-graders addition and subtraction. The GUI should contain two Entry widgets and a Button widget labeled "Enter".

At start-up, your program should generate (1) two single-digit pseudorandom numbers a and b and (2) an operation op, which could be addition or subtraction—with equal likelihood—using the randrange() function in the random module. The expression a op b will then be displayed in the first Entry widget (unless a is less than b and the operation op is subtraction, in which case b op a is displayed, so the result is never negative). Expressions displayed could be, for example, 3+2, 4+7, 5-2, 3-3 but could not be 2-6.

The user will have to enter, in the second Entry widget, the result of evaluating the expression shown in the first Entry widget and click the "Enter" button (or the 'Entetr' key on the keyboard). If the correct result is entered, a new window should say "You got it!".

Augment the GUI you developed so that a new problem gets generated after the user answers a problem correctly. In addition, your app should keep track of the number of tries for each problem and include that information in the message displayed when the user gets the problem right.

Enhance the widget Ed so that it does not repeat a problem given recently. More precisely, ensure that a new problem is always different from the previous 10 problems.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

from tkinter import *
import random
wrongcount=0
def check():
   global wrongcount
   x=int(e2.get())
   if(x==res):
       win=Toplevel(master)
       txt="No. of tries: "+str(wrongcount+1)
       tries=Label(win,text=txt)
       e1.delete(0,END)
       e2.delete(0,END)
       prblmgenerate()
       e1.insert(END,exp)
       display=Label(win,text="You got it!")
       display.pack()
       tries.pack()
       wrongcount=0
      
   else:
       wrongcount=wrongcount+1
       print("you are wrong")
      


def prblmgenerate():
   global exp
   global res
   a=random.randrange(0,10)
   b=random.randrange(0,10)
   oplist=['+','-']
   op=random.choice(oplist)
   if(op=='+'):
       exp=str(a)+op+str(b)
       res=a+b
   if(op=='-'):
       if(a<b):
           exp=str(b)+op+str(a)
           res=b-a
       else:
           exp=str(a)+op+str(b)
           res=a-b
  
  

prblmgenerate()
master = Tk()
e1 = Entry(master)
e1.insert(END,exp)
e2 = Entry(master)

e1.grid(row=0, column=1)
e2.grid(row=1, column=1)

Button(master, text='Enter', command=check).grid(row=3, column=0, sticky=W, pady=4)
mainloop()

Output:

Cheaa Studv EXTROOK SC t.Command Promi Microsoft Windo (c) 2017 Micros 9-7 10 C: Users LENOV Enter C:\UsersLENOVO Desktop>pyt

rights rese You got it! No. of tries: 2 p py

io 0+3 2 Enter pa

You got it! No. of tries: 1

Add a comment
Know the answer?
Add Answer to:
Python 3+ (using TKinter): 1.) Develop new TKinter GUI widget class Ed that can be used to teach first-graders addition and subtraction. The GUI should contain two Entry widgets and a Button widget la...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • /** * File: GradeCalculator . java * Description: Instances of this class are used to calculate...

    /** * File: GradeCalculator . java * Description: Instances of this class are used to calculate * a course average and a letter grade. In order to calculate * the average and the letter grade, a GradeCalculator must store * two essential pieces of data: the number of grades and the sum * of the grades. Therefore these are declared as object properties * (instance variables). * Each time calcAverage (grade) is called, a new grade is added to *...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT