In the last discussion, a guessing game was developed. The code was as follows from appuifw import * continue_guess=true while continue_guess: guess_no=random() user_guess=query(u”Enter your guess”, ‘number’) if user_guess is Null: note(u”You have opted out”) continue_guess=false elif user_guess<guess_no: note(u”Your guess is lesser than the goal”) elif user_guess>guess_no: note(u”Your guess is higher than the goal”) else: note(u”Congrats for excellent guess”) user_choice=query(u”Enter Y to continue or N to quit”)
if user_choice is Null or user_choice==’N’: continue_guess=false else: continue_guess=true Now, let us change the display part for displaying the choices. Instead of taking user’s input using a query dialog, let us show a selection list from which the user can select a value. The following code user_guess=query(u”Enter your guess”, ‘number’) needs to be changed to list = [guess-100, guess, guess*200, u”Quit”] user_guess = selection_list(list) First, a list is created using the guess number and its combination. Then the list is given as an argument to the selection_list() method. The returned index, which is the value selected by the user, is then stored in the user_guess variable.
blog comments powered by Disqus |
|
|
|
|
|
|
|