猫史档案馆


猜拳游戏.

用户:_Rise__Rise_查看:0 回复:3 评论:0 创建时间:2020-07-31T12:23:54


import random


print('欢迎来到猜拳游戏')
num = 0
win_num = 0
lose_num = 0
while True:
    if lose_num == 2 or win_num == 2:
        break
    user = int(input('出剪刀打1,出石头打2,出布打3'))
    if user > 3 and user < 1:
        print('不要输入其他数字')
    else:
        AI = random.randint(1,3)
        if (AI == 1 and user == 2) or (AI == 2 and user == 3) or (AI == 3 and user == 1):
            print('你赢了')
            win_num += 1
            num += 1
        elif AI == user:
            print('平局了')
            num += 1
            continue
        elif (AI == 1 and user == 3) or (AI == 2 and user == 1) or (AI == 3 and user == 2):
            print('你输了')
            lose_num += 1
            num += 1
        else:
            if num == 3:
                break
            
if num == 3 and win_num != 2 and lose_num != 2:
    print('游戏结束,没有赢家!')
if win_num == 2:
    print('恭喜你,你赢了!')
if lose_num == 2:
    print('你输了,再接再厉!')

做这个作品主要是觉得学python不能光学不练,然后接做了个这个作品

该作品运用到

基本输入与输出√

运算符√

条件表达式×

选择语句√

循环语句√

break、continue、pass语句√


回复

上一页1 页 / 共 1下一页
ZNS_RemytowerJimmyZNS_RemytowerJimmy

sofa

点赞0


评论


兴奋的乌力哈哈哈兴奋的乌力哈哈哈

板凳

点赞0


评论


1232RvE1232RvE

条件表达式是啥?emotion_doge

点赞0


评论