Exercise 1:
import easygui as g
flavor = g.buttonbox("Please pick your flavor",title = "Icecream Order System",
choices = ("Milk","Vanilla","Strawberry","Matcha"),image = "./ice.gif")
g.msgbox("You picked "+flavor+" flavor ",title = "Icecream Order System",image = "./ice.gif")
Exercise 2:
import easygui as g
number= g.choicebox("Please choose a lucky number",title= "Lucky number",choices= ("0","1","2","3","4","5","6","7","8","9"))
g.msgbox("What you selected is "+number,title= "Lucky number")
Exercise 3:
import easygui as g
flavor= g.enterbox("Please enter your favorite flavor",title= "Ice cream ordering system")
g.msgbox("What you entered is "+flavor+" taste",title= "Ice cream ordering system")
Exercise 4:
import easygui as g
num = g.enterbox("Please input an integer",title = "test")
number = int(num)
g.msgbox(msg ="You input: "+number)#you will get an error here
Exercise 5:
import easygui as g
score= g.integerbox("Please enter your score",title= "Achievements",lowerbound= 0,upperbound= 100)
g.msgbox("your score is "+str(score))
Exercise 6:
import easygui as g
g.multpasswordbox("Enter username and password",title= "User login interface",fields= ("username","password"))
Homework:
import easygui as g
name = g.enterbox("Please input your name:")
adress = g.enterbox("Please input your address")
tell = g.enterbox("Please input your contact information")
g.msgbox(name+"\n"+adress+"\n"+tell,title = "Delivery Information",ok_button = "Confirm")
Guess Number Game:
import random as r
import easygui as g
secret= r.randint(1,100)
g.msgbox("The computer randomly generated a number ranged 1~100. Please guess this number",title= "Guess number game")
number= g.integerbox("Please enter the number you guess")
while number!= secret:
if number> secret:
g.msgbox("Your guess is too high, please continue guessing")
number= g.integerbox("Please enter the number you want to guess")
else :
g.msgbox("Your guess is too small, please continue guessing")
number= g.integerbox("Please enter the number you want to guess")
g.msgbox("Congratulations, you guessed it correctly. The number randomly generated by the computer is "+(str(secret)))
[…] 4 Basic Operations| |____Unit 5 Data Types| |____Unit 6 Data Input| |____Unit 7 GUI design I| |____Unit 8 GUI design II|____Python Level 2| |____Unit 9 bool data type and relational operators| |____Unit 10 if statement| […]