博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python条件语句嵌套
阅读量:4170 次
发布时间:2019-05-26

本文共 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."

运行该代码多次,执行结果如下图:

你可能感兴趣的文章
MySQL存储引擎底层常见面试题
查看>>
MySQL Explain执行计划详解
查看>>
索引最佳实践具体实例
查看>>
临时关闭MySQL缓存
查看>>
HBase学习和使用
查看>>
LSTM
查看>>
牛客网 数字游戏
查看>>
逆波兰表达式
查看>>
逆波兰表达式
查看>>
K-means中K值的选取
查看>>
kmeans优化算法
查看>>
牛客网 构造队列
查看>>
牛客网 跳石板
查看>>
牛客网 最大的奇约数
查看>>
python大坑:AttributeError: 'module' object has no attribute 'Workbook'
查看>>
python 协程
查看>>
在写计算器时学到的
查看>>
小Q的歌单
查看>>
牛客网 计算机网络 选择题及知识点 (1)
查看>>
0-1背包问题
查看>>