小编Joh*_*ell的帖子

Python:当我有一个if语句和一个打印分配给3个整数,并且我输入一个更高的时候,它给出了这两个,并且正确的打印

对不起,如果我只是愚蠢,但我是python的新手.当我执行此操作并键入一个高于7的数字时,它会给出5,6和7的答案,以及> 7打印.它告诉我,"我希望它越过边界变成令人敬畏的",然后"那真棒".PS我正在使用Python 3

print ('What is your name?')
LeName = input ()
print (' How are you, ' + LeName + '?')
print ('On a scale of one to ten, what would you rate your day so far?')
mood = int (input())
if mood <4:
    print ('That\'s horrible, I hope it gets better.')
if mood == '5' '6' or '7':
    print('Hope it crosses the border into awesome! :)')
if mood > 7:
    print('That\'s awesome!')
print ()
Run Code Online (Sandbox Code Playgroud)

发布后大约半小时我想到了它,如果情绪='5''6'的'7'就改变了,如果情绪> =和情绪<8但是我仍然很好奇为什么会发生这种情况.谢谢你的答案.

python python-3.x

3
推荐指数
1
解决办法
133
查看次数

随机短语创作者

我想创建一个程序,通过创建10个从1到20的随机整数来生成随机短语,并且根据每个变量整数,将生成某个单词或短语.有没有比以下更简单的方法:

#This is a random phrase generator
import random
Rand1 = random.randint (1, 20)
Rand2 = random.randint (1, 20)
Rand3 = random.randint (1, 20)
Rand4 = random.randint (1, 20)
Rand5 = random.randint (1, 20)
Rand6 = random.randint (1, 20)
Rand7 = random.randint (1, 20)
Rand8 = random.randint (1, 20)
Rand9 = random.randint (1, 20)
Rand10 = random.randint (1, 20)
    if Rand1 ==1:
        print ('Squirrel')
Run Code Online (Sandbox Code Playgroud)

等等... PS使用Python 3

感谢您提供有用的建议.我是python的新手,让那些可以帮助我创建更好代码的人非常有帮助.如果有人关心,我用这个与你交谈的程序,让你有机会听到笑话和玩几个游戏.祝你今天愉快.

PPS我最终选择了:

import random
words = 'squirrel orca ceiling crayon boot grocery jump' …
Run Code Online (Sandbox Code Playgroud)

python python-3.3

1
推荐指数
1
解决办法
3178
查看次数

Python 3,IDLE表示变量未定义,但确实如此

我正在创建一个输入密码的程序,你可以玩游戏.在我定义一个riddle(),它告诉我d1,d2,d3,d4,和d5在定义之前,他们被引用,但据我所知,他们已经确定.此外,当这仍然有效时,我试图让它解决一个任务会让它说它已经完成,但当我完成一个时,它仍然说1是不完整的等等.我需要解决这两个问题.

def riddle():
    d1 = 'n'
    d2 = 'n'
    d3 = 'n'
    d4 = 'n'
    d5 = 'n'
    def compcheck():
        print('There are 5 tasks to complete. Enter a number to see task.')
        if d1 in ('y'):
            t1 = 'Completed.'
        if d2 in ('y'):
            t2 = 'Completed.'
        if d3 in ('y'):
            t3 = 'Completed.'
        if d4 in ('y'):
            t4 = 'Completed.'
        if d5 in ('y'):
            t5 = 'Completed.'
        if …
Run Code Online (Sandbox Code Playgroud)

python python-3.x

0
推荐指数
1
解决办法
289
查看次数

标签 统计

python ×3

python-3.x ×2

python-3.3 ×1