Jan*_*pez 1 python if-statement
您好,我目前正在努力掌握Python中的if,elif,else结构.我在python中尝试了一些奇怪的组合,有一个测试程序来知道if if,if,elif,elif,else代码中的输出.但是我得到了这样奇怪的结果
input = raw_input('Please enter the required digit: ')
intput = int(input)
if intput == 0:
print 'if1'
if intput == 1:
print 'if2'
elif intput == 0:
print 'elif1'
elif intput == 1:
print 'elif2'
else:
print 'else'
Run Code Online (Sandbox Code Playgroud)
如果我在1中它将打印"if2",我认为当我尝试更改"intput == n"代码时,它还会打印"elif2"和其他恶作剧.所以我的问题是我必须坚持使用if,elif,elif,.... n*elifs,否则我认为工作正常的方法比使用古怪如果,如果.... n*ifs,elif ,elif,... n*elifs,否则.
谢谢