I'm very new to Python but have written a simple Rock, Paper, Scissors game.
It's code is as follows:
from __future__ import print_function
import random
name = raw_input("Hi, I'm PyVa. What is your name: ")
print('Hi',name, end='.')
yesorno = raw_input(' Would you like to play Rock, Paper, Scissors?: ')
yesorno = str(yesorno)
if yesorno == str('Yes'):
choices = ['Rock', 'Paper', 'Scissors']
print('Ok')
your_choice = raw_input('Choose Rock, Paper or Scissors: ')
print('My turn...')
my_choice = random.choice(choices)
print('I choose,', my_choice)
if your_choice == my_choice:
print('We both choose the same, it is a draw.')
elif your_choice == 'Rock' and my_choice == 'Paper':
print('I win!')
elif your_choice == 'Scissors' and my_choice == 'Paper':
print('You win!')
elif your_choice == 'Paper' and my_choice == 'Rock':
print('You win!')
elif your_choice == 'Paper' and my_choice == 'Scissors':
print('I win!')
elif your_choice == 'Rock' and my_choice == 'Scissors':
print('You win!')
elif your_choice == 'Scissors' and my_choice == 'Rock':
print('I win!')
again = raw_input('Would you like to play again?:')
#this is where I would like to loop to the start depending on input.
else:
print('Ok, maybe we can play later, bye.')
Now I can imagine this isn't even remotely elegant code and that there must be more precise ways to write what I am trying to do. (Please give any pointers you have time to).
My main concern is how to correctly insert a loop for after each game ends to either return to the second block ie. the start or the game, or to simply end, based on the raw_input from the user.
Many thanks for any help you can give.
str('Yes').'Yes'is already a string. The same applies to the return value ofraw_input.