第二課 示範程式
石頭, 布, 剪刀 遊戲
from random import randint
choice = ["石頭","布","剪刀"]
def main():
電腦 = choice[randint(0,2)]
print("Welcome to the 石頭, 布, 剪刀 遊戲\n")
你 = input("Your Choice: ").lower()
print("電腦: " + 電腦)
if 你 == 電腦:
print("平手")
elif 你 == "石頭" and 電腦 == "布":
print("電腦 Wins")
elif 你 == "石頭" and 電腦 == "剪刀":
print("你 Wins")
elif 你 == "布" and 電腦 == "石頭":
print("你 Wins")
elif 你 == "布" and 電腦 == "剪刀":
print("電腦 Wins")
elif 你 == "剪刀" and 電腦 == "石頭":
print("電腦 Wins")
elif 你 == "剪刀" and 電腦 == "布":
print("你 Wins")
elif 你 == "end":
StopIteration
main()
main()