Python exercise 8 - Rock Paper Scissors

Exercise 8 - Rock Paper Scissors

'''
Make a two-player Rock-Paper-Scissors game. (Hint: Ask for player plays (using input), compare them, print out a message of congratulations to the winner, and ask if the players want to start a new game)

Remember the rules:
Rock beats scissors
Scissors beats paper
Paper beats rock
'''

Code:

print('Game Start')
player1_name = input('Please enter your name(player1):')
player2_name = input('Please enter your name(player2):')
	
def compare():
	player1_enter=str(input('%s, Please choose your decision: Rock, Scissors, or Paper? '%(player1_name)))
	player2_enter=str(input('%s, Please choose your decision: Rock, Scissors, or Paper? '%(player2_name)))
	if player1_enter in ['Rock','Scissors','Paper'] and player2_enter in ['Rock','Scissors','Paper']:
		print (player1_name+': '+player1_enter)
		print (player2_name+': '+player2_enter)
		if player1_enter == player2_enter:
			print ('Draw')
		elif player1_enter=='Rock':
			if player2_enter=='Scissors':
				print ('Congratulations! '+player1_name+', You win!')
			else:
				print ('Congratulations! '+player2_name+', You win!')
		elif player1_enter=='Scissors':
			if player2_enter=='Paper':
				print ('Congratulations! '+player1_name+', You win!')
			else:
				print ('Congratulations! '+player2_name+', You win!')
		elif player1_enter=='Paper':
			if player2_enter=='Rock':
				print ('Congratulations! '+player1_name+', You win!')
			else:
				print ('Congratulations! '+player2_name+', You win!')
	else:
		print ('Invalid enter, Please enter your decision again.')
		return compare()
	
compare()
while True:
	restart_game=input('Do you want to restart the game? enter Y or N:')
	if restart_game=='Y':
		print('Game restart')
		compare()
	else:
		print('Game Over')
		break
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值