本文共 469 字,大约阅读时间需要 1 分钟。
在程序中,if语句可以嵌套,同等缩进为同一条件结构,下面我们通过几行python2代码,学习一下条件嵌套。
使用python(x,y),代码如下:
k=raw_input("input the index of shape:")
if k=='1':
print "circle" elif k=='2': print "oval" elif k=='3': print "rectangle" s1=int(raw_input('the first side:')) s2=int(raw_input('the second side:')) if s1==s2: print "the square's area is:%d." % (s1*s2) else: print "the rectangle's area is:%d." % (s1*s2) elif k=='4': print "triangle" else: print "you input the invalid number."运行该代码多次,执行结果如下图: