Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Snake Water Gun Game
- Source code:Divyansh Chourey
- '''
- import random
- run=True
- #Function for declaring result
- def game():
- """docstring for game"""
- if user=='s':
- if comp=='s':
- return 'tie'
- elif comp=='w':
- return 'User won'
- elif comp=='g':
- return 'User lost'
- elif user=='w':
- if comp=='s':
- return 'User lost'
- elif comp=='w':
- return 'tie'
- elif comp=='g':
- return 'User won'
- elif user=='g':
- if comp=='s':
- return 'User won'
- elif comp=='w':
- return 'User lost'
- elif comp=='g':
- return 'tie'
- # TODO: write code...
- display='Welcome to SWG\nYou have the follwing options:\n\tSnake(s)\n\tWater(w)\n\tGun(g)'
- print(display)
- #Using while loop to run the game
- while run:
- #Taking the input from user
- user=input("\nEnter: ")
- #Generating random number
- rand_num=random.randint(1,3)
- #Converting the random digit to a variable
- if rand_num==1:
- comp="s"
- elif rand_num==2:
- comp="w"
- elif rand_num==3:
- comp="g"
- #Exit from the game
- if user=='quit':
- print("You quit the game")
- break
- else:
- run = True
- result=game()
- #displaying the final results
- if result=='User won':
- result="You won\n"
- elif result=='User lost':
- result="You lose\n"
- elif result=='tie':
- result="TIE!\n"
- dis_result='\nComputer chose: '+comp+'\nYou chose: '+user+'\nResult: '+result
- print(dis_result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement