社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

Raunak Raj

Raunak Raj 最近创建的主题
Raunak Raj 最近回复了
3 年前
回复了 Raunak Raj 创建的主题 » Python if and else语句不是预期的输出

使用下面的代码它对我有用。

def check_guess(guess, answer):
    global score
    global name
    still_guessing = True
    attempt = 0
    while still_guessing and attempt < 3:
        if guess == answer:
            print('Correct wow, i expected worse from someone named %s' % name)
            if attempt == 0:
                score = score + 3
            elif attempt == 1:
                score = score + 2
            elif attempt == 2:
                score = score + 1
            still_guessing = False
        elif attempt <= 2:
            print('HAAAAAAAAAAAAAAAAAAAAAAAAAAAA IMAGINE NOT GETTING THAT RIGHT!!!')
            print('L bozo + ratio')
            guess = input('Try again ')
            attempt = attempt + 1
    if attempt == 3:
        print('the correct answer was %s' % answer)
        print('There is always next time!!')
        still_guessing = False
score = 0
print('Welcome to the animal quiz')
print()
print('In this game you will have to guess the animal')
name = input('What is your name? ')
print('Cool name, I feel like i heard of it before hmmm %s..' % name)
print()
print('Enough stalling onto the game!!!')
guess1 = input('Which bear lives in the north pole ')
check_guess(guess1.strip().lower(), 'polar bear')