Try And Except Problems In Python 2.7
I am trying to write a piece of code that asks the user if they want to restart and if so, it does so and if not, it says thanks for playing.
import os import time while True: try: print "He walks past you but then doubles back, he crouches down, you scream and try to grab the brick but your too slow,5 bullets penetrate your chest and go through your heart. Blood is coming out of your mouth, gagging on your own blood the last thing you see is him turning around and walking away. You died." death1 = raw_input ("Do you want to restart:") time.sleep(1) os.system('clear') except: if death1 == str("yes"): continue elif death1 == str("no"): print "Thanx for playing" break
Currently, as long as the user types in anything it will re-ask the question. Is there a way to make it so if they say no, it says thanks for playing?
while True: # game logic here want_restart = raw_input("Do you want to restart?") want_restart = want_restart.lower() == "yes" if not want_restart: break print("Game ended. Thanks for playing")
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module