Next, let us change how the result is processed. To do so, change the code below 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”) to the following if guess_no < list [user_guess]: note(u”Your guess is lesser than the goal”) elif guess_no < list [user_guess]: note(u”Your guess is higher than the goal”) elif guess_no == list [user_guess]: note(u”Congrats for excellent guess”) else: note(“Bye”) continue_guess = false The index returned by the selection_list() is used by the if condition to get the value selected by the user, from the list. If the index corresponds to the value lesser or greater than the goal value, then a note is displayed telling the user that he/she is either short of the goal or has overshot the goal. Otherwise, the user is congratulated. If the user selected the option to quit, the continue_guess is set to false, thus ending the game. The complete code is as follows: from appuifw import * continue_guess=true while continue_guess: guess_no=random() list = [guess-100, guess, guess*200, u”Quit”] user_guess = selection_list(list) if guess_no < list [user_guess]: note(u”Your guess is lesser than the goal”) elif guess_no < list [user_guess]: note(u”Your guess is higher than the goal”) elif guess_no == list [user_guess]: note(u”Congrats for excellent guess”) else: note(“Bye”) continue_guess = false That completes our application. This discussion focused on the UI controls. When I next pick up this discussion, I will bring up third party libraries in PyS60. However, I will focus primarily on the graphics module. Till then…
blog comments powered by Disqus |
|
|
|
|
|
|
|