社区所有版块导航
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
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

Python if and else语句不是预期的输出

Kbeast • 3 年前 • 1112 次点击  

我想用python 3.9做一个动物测试。在其中一个问题上,犯了三次错并不能像应该的那样开始一个新问题。相反,它只是一片空白。在第一次和第二次尝试时,一切都很顺利。感谢您的任何帮助。这是我的代码:

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 <= 1:
            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')
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/130615
 
1112 次点击  
文章 [ 5 ]  |  最新文章 3 年前