对不起,如果我只是愚蠢,但我是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但是我仍然很好奇为什么会发生这种情况.谢谢你的答案.
我想创建一个程序,通过创建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) 我正在创建一个输入密码的程序,你可以玩游戏.在我定义一个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)