码迷,mamicode.com
首页 > 编程语言 > 详细

Python if-else and while

时间:2018-06-24 15:08:09      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:分享图片   style   http   and   int   tab   class   bubuko   src   

if-elif语法

if condition:
[tab键] command
elif condition:
[tab键] command
elif condition:
[tab键] command
else:
[tab键] command


while语法

while condition:
[tab键] command


if嵌套

if condition:
[tab键] command
[tab键] if condition:
[tab键] [tab键] command
[tab键] else:
[tab键] [tab键] command
else:
[tab键] command
#-*- coding:utf-8 -*-

#双循环打印矩形

#矩形长度是7,宽度是5

i = 0
j = 0

while i < 5:
        j = 0
        while j < 7:
                if (i == 0) or (i == 4):
                        #这种end=""不换行操作是python3.x版本支持的,python2.x下会报错
                        print("*",end=‘‘)
                else:
                        if (j == 0) or (j == 6):
                                print("*",end = "")
                        else:
                                print(" ",end=‘‘)
                j += 1
        print("")
        i += 1

技术分享图片

技术分享图片

Python if-else and while

标签:分享图片   style   http   and   int   tab   class   bubuko   src   

原文地址:https://www.cnblogs.com/zhanggaofeng/p/9220439.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!