python--分支语句&循环语句

x=int(raw_input("Please enter an integer:"))
if x<0:
    x=0
    print "Negative changed to zero"

elif x==0:
    print "Zero"

else:
    print "More"

 

运行结果:

Please enter an integer:0
Zero

 

 

a = ['cat', 'window', 'defenestrate']
for x in a:
    print x, len(x)

 

运行结果:

cat 3
window 6
defenestrate 12

你可能感兴趣的:(python)