You guess heads or tails by clicking one of the buttons on easyGUI.  If it's right, you will get a good job message.  If it's wrong, you will get a wrong message! After that, there is an option to play again.Please give me some feedback on how I can make my code better, if there is room for improvement.import randomimport timeimport easyguiimport syswhile True:    rand = random.choice([Heads, Tails])    firstguess = easygui.buttonbox(Pick one, choices= [Heads, Tails])    if firstguess == rand:        easygui.msgbox(Wow you win!)    else:    easygui.msgbox(Sorry you guessed wrong!)    time.sleep(2)    answer = easygui.buttonbox(Play again?, choices=[Yes,No])    if answer == Yes:        pass    else:        breakeasygui.msgbox(Ok, see you later!)sys.exit(0)
Guessing Game (Heads or Tails)
python;beginner;game
Your script isn't bad. But there is always room for improvement:It's bad to mix tabs and spaces.  The fact that your code broke when you pasted it here shows why.  Good editors have a setting that will help you with this.  (It is recommended that you use spaces only.)You don't need sys.exit(0) at the end of your script, since Python will exit automatically when it reaches the end.Choose your variable names carefully. rand is not very descriptive and firstguess is plain incorrect (every guess, not just the first, gets assigned to this variable).Don't repeat yourself.  Don't write [Heads, Tails] twice, because if you have to change it for whatever reason, you have to remember to change it in two places.  Store it in a variable.You can simplify this:if answer == Yes:    passelse:    breakTo this:if answer != Yes:    breakI don't know easygui, but it seems you should use aynboxwhen you're asking yes or no?.  So you can change this:answer = easygui.buttonbox(Play again?, choices=[Yes,No])if answer != Yes:    breakTo this:play_again = easygui.ynbox(Play again?)if not play_again:    breakOr simply:if not easygui.ynbox(Play again?):    breakWith all the changes made and after applying the rules from the the Python style guide PEP8, your code looks like this:import random    # alphabetic orderimport timeimport easygui    # third-party modules after standard-library modulesCHOICES = [Heads, Tails]    # ALL_CAPS for variables whose value never changeswhile True:    result = random.choice(CHOICES)    guess = easygui.buttonbox(Pick one, choices=CHOICES)    if guess == result:        easygui.msgbox(Wow you win!)    else:        easygui.msgbox(Sorry you guessed wrong!)    time.sleep(2)    if not easygui.ynbox(Play again?):        breakeasygui.msgbox(Ok, see you later!)