python if语句

if 语句用于有条件的执行。

语法:

if 表达式:执行语句

elif 表达式:执行语句

else:执行语句

应用范例:石头剪刀布

import random
player = int(input("请出拳 石头(1)/剪刀(2)/布(3):"))
computer = random.randint(1,3) 
print("你出的是:", end = "")
print(player)
print("电脑出的是:", end = "")
print(computer)
if ((player == 1 and computer == 2) or
        (player == 2 and computer == 3) or
        (player == 3 and computer == 1)):
    print("噢耶!!!电脑弱爆了!!!")
elif player == computer:
    print("心有灵犀,再来一盘!")
else:
    print("不行,我要和你决战到天亮!")

 

posted @ 2020-08-05 12:08  轩辕吊雷  阅读(166)  评论(0编辑  收藏  举报