用循环实现简单21点游戏

user_point = 0
computer_point = 0
random_user = 0
user_name = input("please input gamer name:")
while user_point <=21 and computer_point <= 21:
    if user_point <= 21:
        random_user = random.choice(range(0,16))
        if random_user >= 11:
            user_point += 0.5
        else:
            user_point += random_user
    if computer_point <=21:
        random_computer = random.choice(range(0,16))
        if random_computer >= 11:
            computer_point += 0.5
        else:
            computer_point += random_computer
print("%s"%computer_point)
print("%s"%user_point)
if user_point > computer_point >21 or user_point ==21:
    print("player win!")
elif user_point ==computer_point:
    print("peace")
else:
    print("computer win")

  

posted on 2019-07-26 10:16  阿o·O  阅读(172)  评论(0编辑  收藏  举报