#!/usr/bin/python3
#_*_ coding:utf-8 _*_
#Time:2019/10/15 9:30
#用while循环输出1,2,3,4,5,6,8,9,10
count=0
while count<11:
count+=1
if count==7:
pass
else:
print(count)
#!/usr/bin/python3
#_*_ coding:utf-8 _*_
#Time:2019/10/15 9:41
#输出1-100内的奇数
#分析:
#1:先输出1-100个数
#2:判断奇数成立的条件:num%2!=0(两个奇数之间的结果相差2)
# count=0
# while count<101:
# print(count)
# count+=2
#方法二:
# count=0
# while count<101:
# if count%2==1:
# print(count)
# count += 1
#方法三
#注意:==表示比较,=表示赋值
count=0
while count<101:
count += 1
if count%2==0:
continue
else:
print(count)
#!/usr/bin/python3
#_*_ coding:utf-8 _*_
#Author:gaoyuxia
#Time:2019/10/15 9:45
#求1+2+3+4.。。。+99的和
count=0
sum=0
while count<=100:
sum+=count
count+=1
print(sum)
#!/usr/bin/python3
#_*_ coding:utf-8 _*_
#Time:2019/10/15 10:18
#用户登陆(三次)
username="xiaoming"
password="123"
count=0
while count<3:
username = input("请输入用户名:")
password = input("请输入密码:")
if username=="xiaoming" and password=="123":
print("登录成功")
else:
print("帐号密码输入错误")
count+=1
format格式化输出
#!/usr/bin/python3
#_*_ coding:utf-8 _*_
#Time:2019/10/15 10:30
#格式化输出
#%s===%:占位符,s:占位符类型是string类型
#%d====d:int类型
name=input("请输入姓名:")
age=input("请输入年龄:")
hobbie=input("请输入爱好:")
job=input("请输入工作:")
#在此处如果想要输出%,需要添加%%
msg="姓名:%s,年龄:%s,爱好:%s,工作:%s,学习进度为3%%" %(name,age,hobbie,job)
print(msg)
message='''----------info %s------
name:%s
age:%d
hobbie:%s
job:%s
----------end------''' %(name,name,int(age),hobbie,job)
print(message)
while else
当while循环被break打断,将不会执行else,当while循环没有被break打断,将会执行else
![](https://img2018.cnblogs.com/blog/1567266/201910/1567266-20191015111227340-24248331.png)
快速注释:ctrl+/
快速取消注释:ctrl+/
python缩进是四个空格