小编Mam*_*ury的帖子

如何阻止我的 Python if 语句与我的 else 语句一起打印?

我只是在学习 python 并且无法理解为什么我的 if 输入触发了我的 else 语句。我确定我在这里遗漏了一些基本的东西,但希望有人看一下!本质上,当我输入一个变量时,它会将 else 语句拖入其中。我附上代码,谢谢您的观看!

n = 'Nike'
p = 'Puma'
a = 'Adidas'

boot = input('What is your favorite boot?')

if boot == n:
  print('Nike, great choice')
if boot == a:
  print('Adidas, not my favorite')
if boot == p:
  print('Not sure about Puma')
else:
  print('I am not familiar with that brand')
Run Code Online (Sandbox Code Playgroud)

Nike输入打印上打字

Nike, great choice.
I'm not familiar with that brand.
Run Code Online (Sandbox Code Playgroud)

python if-statement

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

标签 统计

if-statement ×1

python ×1