---
# System prepended metadata

title: 12571 - Python2020 Quiz7 Problem1
tags: [Quiz]

---

# 12571 - Python2020 Quiz7 Problem1 
###### tags: `Quiz`

[TOC]

## Description
Write a "rock, paper, scissors" game using the random module.
The program first prompts the user for 'rock', 'paper', or 'scissors'. Then it randomly generates one to compete with the user and report whether the user wins, loses, or tied. If the user enters other words, it reports 'invalid!'. The game goes infinitely until the user enters 'quit'.

The program should take an integer from the input at the beginning and use it as the seed value for the random module so that the random results will be predictable for us.
For example, if you set the seed value to 0 and take a choice from the list ['rock', 'paper', 'scissors'] using random.choice function for 4 times, it always chooses 'paper', 'paper', 'rock', and 'paper'.

[Note] Please do use the random.choice function to choose from the list ['rock', 'paper', 'scissors'].

Below is one example (`highlight` for user input and black for progam output):

`0`
rock, paper, scissors?
`rock`
I'm paper, you lose!
rock, paper, scissors?
`paper`
I'm paper, tied!
rock, paper, scissors?
`rock`
I'm rock, tied!
rock, paper, scissors?
`scissors`
I'm paper, you win!
rock, paper, scissors?
`rabbit`
invalid!
rock, paper, scissors?
`quit`
bye!

#### Input
A sequence of user inputs and end with a 'quit'.

##### Sample Input
```
3
rock
scissors
paper
lion
quit
```
#### Output
The prompts and the responses.

##### Sample Output
```
rock, paper, scissors?
I'm rock, tied!
rock, paper, scissors?
I'm scissors, tied!
rock, paper, scissors?
I'm scissors, you lose!
rock, paper, scissors?
invalid!
rock, paper, scissors?
bye!
```

## Solution

```python
import random
seed_value = int(input())
random.seed(seed_value)
L = ['rock', 'paper', 'scissors']
while True:
	player = input('rock, paper, scissors?\n')
	if player == 'quit':
		print('bye!')
		break
	elif player not in L:
		print('invalid!')
	else:
		Com = random.choice(L)
		a = L.index(player)
		b = L.index(Com)
		if (a-b+3)%3 == 1:
			print(f"I'm {Com}, you win!")
		elif (b-a+3)%3 == 1:
			print(f"I'm {Com}, you lose!")
		else:
			print(f"I'm {Com}, tied!")

```