Python - 在if,elif,else语句中打印

时间:2014-10-02 21:03:57

标签: python if-statement

我希望这段代码不打印"你猜对了。"和#34;你有......"如果"如果"声明是错误的,但如果" elif"和"否则"陈述是真的。

有没有一种简单的方法可以做到这一点,而无需在" elif"和"否则"声明?

def input_guess(guess):

    ....

    print 'You guessed: ', guess_num,'.',
    print 'You have', remainding_guess_times, 'guesses left.',

    if guess_num == real_num:
        print 'Congratulations, blablabla!'
        new_game()
    elif guess_num > real_num:
        print 'blablabla'
    else:
        print 'blablabla'

    ...

1 个答案:

答案 0 :(得分:0)

def input_guess(guess):

    ....

    if guess_num == real_num:
        print 'Congratulations, blablabla!'
        new_game()
    else:
        print 'You guessed: ', guess_num,'.',
        print 'You have', remainding_guess_times, 'guesses left.',

        if guess_num > real_num:
            print 'blablabla'
        else:
            print 'blablabla'