【发布时间】:2020-10-01 17:38:53
【问题描述】:
我刚刚开始编码,每天都像婴儿一样成长
复习我的笔记并尝试理解/记住代码会变得很困难。
请解释一下如何处理这段代码。
from random import randint
"""This program will enable the user and computer to start a rock paper scissors game"""
options = ["ROCK", "PAPER", "SCISSORS"]
message = {"tie": "Yawn it's a tie!", "won": "Yay you won!", "lost": "Aww you lost!"}
def decide_winner(user_choice, computer_choice):
print("You chose %s") % (user_choice)
print("PC chose %s") % (computer_choice)
if user_choice == computer_choice:
print(message["tie"]) # tie
# user - paper , pc = rock
elif user_choice == options[1] and computer_choice == options[0]:
print(message["won"])
# user - scissor , pc = paper
elif user_choice == options[2] and computer_choice == options[1]:
print(message["won"])
# user - rock , pc - scissors
elif user_choice == options[0] and computer_choice == options[1]:
print(message["won"])
else:
print("YOU LOSE!")
def play_RPS():
user_choice = input("Enter Rock, Paper, Scissors: ")
computer_choice = options[randint(0,2)]
decide_winner(user_choice, computer_choice)
play_RPS()
【问题讨论】:
-
请说出你目前所了解的。