python 基础语句

1、用户交换程序

import getpass
username = input('请输入你的名字:')
passwd = getpass.getpass('请输入密码')
age = input('请输入你的年龄:')
print("欢迎你来到python 姓名:%s 年龄:%s"%(username,age)

2、if else语句

age = input("请输入你的年龄")
if age.isdigit():
    if int(age) <20:
        print("你还年轻")
    elif int(age) >=20 and int(age)<=40:
        print("人到中年")
    else:
        print("你已经老了")

3、while循环

count = 0
while count <3:
passwd = input('请输入密码:')
if passwd == '123456':
break
count += 1
if count == 3:
countinue_confirm = input("是否继续 y/n:")
if countinue_confirm == 'y':
count = 0
else:
print("你输入的过多")

4、for循环

new_flag = True
while new_flag:
    for i in range(0,10,2):
        if i >5:
            continue
        print('bad')
        print('loop',i)

 

posted @ 2017-06-28 23:13  Allen_GC  阅读(158)  评论(0)    收藏  举报