Combine your Game1 program (the guessing game) with the graphics program I posted. Your "windows" program should display a window and ask the user to guess the number, accept the guess from the user, and then display the appropriate response to the guess. Game 1 #Import module import random #Generate random number n=int(random.randint(1,10)) #Prompt the user to guess a number print("Guess a number : ") #Get the guess from the user guess=int(input()) #Check if both are equal if guess==n: #Print the message print("Success!!!") else: #Print the message print("Sorry") Graphics code: Listing of my Window.300.by.400 program: # This shows how to output strings to the graphics window # and get user input # # basic steps # create and use a Text object to output the label / prompt # create and use an Entry object to allow the user to type # put some text into the Entry object (setText) # use a getMouse to pause until user clicks # use getText to get the input from the Entry object # process input as desired from graphics import * def main(): win = GraphWin("Sample Input", 300, 400) win.setCoords(0,0, 299, 399) # not required, just convenient upleft= Text(Point(50, 350),"50, 350") upleft.setStyle('bold italic') # not required, just convenient upleft.draw(win) upright= Text(Point(250, 350),"350, 350") upright.setStyle('bold italic') # not required, just convenient upright.draw(win) downleft= Text(Point(50, 50),"50, 50") downleft.setStyle('bold italic') # not required, just convenient downleft.draw(win) downright= Text(Point(250, 50),"350, 50") downright.setStyle('bold italic') # not required, just convenient downright.draw(win) prompt = Text(Point(150, 50),"Click to end") prompt.draw(win) win.getMouse() win.close() main()
Combine your Game1
Game 1
#Import module
import random
#Generate random number
n=int(random.randint(1,10))
#Prompt the user to guess a number
print("Guess a number : ")
#Get the guess from the user
guess=int(input())
#Check if both are equal
if guess==n:
#Print the message
print("Success!!!")
else:
#Print the message
print("Sorry")
Graphics code:
Listing of my Window.300.by.400 program:
# This shows how to output strings to the graphics window
# and get user input
#
# basic steps
# create and use a Text object to output the label / prompt
# create and use an Entry object to allow the user to type
# put some text into the Entry object (setText)
# use a getMouse to pause until user clicks
# use getText to get the input from the Entry object
# process input as desired
from graphics import *
def main():
win = GraphWin("Sample Input", 300, 400)
win.setCoords(0,0, 299, 399) # not required, just convenient
upleft= Text(Point(50, 350),"50, 350")
upleft.setStyle('bold italic') # not required, just convenient
upleft.draw(win)
upright= Text(Point(250, 350),"350, 350")
upright.setStyle('bold italic') # not required, just convenient
upright.draw(win)
downleft= Text(Point(50, 50),"50, 50")
downleft.setStyle('bold italic') # not required, just convenient
downleft.draw(win)
downright= Text(Point(250, 50),"350, 50")
downright.setStyle('bold italic') # not required, just convenient
downright.draw(win)
prompt = Text(Point(150, 50),"Click to end")
prompt.draw(win)
win.getMouse()
win.close()
main()
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images