python创建提示用户输入查询条件_python流程控制练习
‘’’
if条件
‘’’
示例
sex= ‘female’
age=19
is_beautiful=True
is_successful=True
height=1.70
if sex ==‘female’ and age > 18 and age <20 and is_beautiful \
and height > 1.6 and height < 1.8 :
print(“001”)
if is_successful :
print(‘ok’)
else:
print(‘sb’)
else:
print(‘88’)
#示例2
score=int(input(‘你的成绩:’))
# score=int(score)
if score >= 90:
print(“优秀”)
elif score >= 80:
print(“良好”)
elif score >= 70:
print(“普通”)
else:
print(“很差”)
while循环
tag=True
while tag:
name=input(‘your name is:’)
# pwd=input(‘your pass word is:’)
pwd=int(input(‘your pass word is:’))
if name==‘aaa’ and pwd==111:
# if name == ‘aaa’ and pwd == ‘111’:
print(‘login successful’)
else:
print(‘try again’)
print(">>>>")
while结束循环方式一:
将条件改成false
tag = True
while tag:
name = input(‘your name is:’)
# pwd=input(‘your pass word is:’)
pwd = int(input(‘your pass word is:’))
if name == ‘aaa’ and pwd == 111:
# if name == ‘aaa’ and pwd == ‘111’:
print(‘login successful’)
tag = False
else:
print(‘try again’)
print(">>>>")
while结束方式二 while+continue 结束本次循环,直接进入下一次循环
count = 1
while count < 6:
if count == 4:
count += 1
continue
print(count)
count += 1
# count += 1
‘’‘需求设计一个登陆程序
要求1、输入正确的用户名和密码
要求2、登陆失败后无限次重新输入
要求3、登陆成功后结束程序并打印>>>,’’’
尝试1
name = input(‘your login name:’)
pwd = input(‘your passwords :’)
tap = True
while tap :
if name == ‘bob’ and pwd ==‘111’:
print(‘login successful’)
tap = False
else:
print(‘username or passsword error’)
tap = False
print(’>>>>>’) #都打印>>>,但是只有一次登陆机会
尝试2
while True:
name = input(‘your login name:’)
pwd = input(‘your password :’)
if name == ‘bob’ and pwd == ‘11’:
print(‘login successful’)
break
else:
print(‘user name or password error’)
break
print(’>>>’) #成功打印>>>,失败也打印>>> 但是只有一次尝试机会
尝试3
while True:
name = input(‘please input your login name:’)
pwd = input(‘please input your password :’)
if name == ‘bob’ and pwd == ‘11’:
print(‘login successful’)
break
else:
print(‘user name or password error’)
print(’>>>’) #登陆成功不打印>>>,失败打印>>> 可以无限次重新输入
尝试4
while True:
name = input(‘please input your login name:’)
pwd = input(‘please input your password :’)
if name == ‘bob’ and pwd == ‘11’:
print(‘login successful’,)
print(’>>>’)
break
else:
print(‘user name or password error’)
print(’>>>’)
‘’’
要求1、输入正确的用户名和密码
要求2、只能尝试3次输入错误
要求3、登陆成功后结束程序
‘’’
尝试第一次(运行结果正确,但是程序不停止,错误在while ture,只要更改为while count <4就可以)
count = 1
while True:
if count < 4:
name = input(‘please input your name:’)
pwd = input(‘please input your password:’)
if name == ‘egon’ and pwd == ‘11’:
print(‘login successful’)
break
else:
print(‘username or password error’)
print(’>>>’)
count += 1
count=0
while count < 3:
name=input(‘请输入用户名:’)
password=input(‘请输入密码:’)
if name == ‘egon’ and password == ‘123’:
print(‘login success’)
break
else:
print(‘用户名或者密码错误’)
count+=1
尝试第二次 验证while 循环中嵌套的break会导致else 不运行
count = 1
while True:
if count < 4:
name = input(‘please input your name:’)
pwd = input(‘please input your password:’)
if name == ‘egon’ and pwd == ‘11’:
print(‘login successful’)
break
else:
print(‘username or password error’)
print(’>>>’)
count += 1
else:
print(‘haha’)
尝试第三次 验证将while循环由tap条件终止
count = 1
tap = True
while tap:
if count < 4:
name = input(‘please input your name:’)
pwd = input(‘please input your password:’)
if name == ‘egon’ and pwd == ‘11’:
print(‘login successful’)
tap = False
else:
print(‘username or password error’)
print(’>>>’)
count += 1
else:
print(‘haha’)
‘’’
需求1、输入正确的用户名和密码
要求2、只能尝试3次输入错误,有剩余次数提示
要求3、登陆成功后结束程序
‘’’
count = 3
tag=True
while tag:
if count > 0:
name = input(‘please input your name:’)
pwd = input(‘please input your password:’)
if name == “egon” and pwd == ‘11’:
print(‘login successful’)
break
else:
count -= 1
print(‘username or password error’,\
‘you can try:’,count)
if count==0:
tag=False
练习
1、使用while循环输出1 2 3 4 5 6 8 9 10
‘’'count = 1
while True:
if count != 7:#and count < 11:
print(count)
count += 1
else:
count += 1
if count == 11:
break
#该程序虽然最终结果能按要求打印出结果,但是程序逻辑比较混乱。’’’
‘’‘教师版
count = 1
while count < 11:
if count ==7:
count +=1
continue
print(count)
count += 1
#应用continue语法,当条件成立时,停止当次循环,重新开始循环’’’
#2. 求1-100的所有数的和
count = 1
a = 0
while count < 101:
a=a +count
count += 1
print(a)
#3. 输出 1-100 内的所有奇数
count = 1
while count < 101:
if count % 2 == 1:
print(count)
count += 1
1-100所有奇数的和
count = 1
a = 0
while count<101:
if count %2 == 1:
a = count+a
count += 1
print(a)
1~100所有偶数的和
sum = 0
n = 100
while n > 0:
sum = sum + n
n = n - 2
print(sum)
#4. 输出 1-100 内的所有偶数
‘’‘count = 1
while count<=100:
if count %2==0:
print(count)
count += 1’’’
#5. 求1-2+3-4+5 … 99的所有数的和
count = 1
a = 0
while count < 100:
if count % 2 == 1:#99
a = a + count
count += 1
else:
a=a - count
count += 1
print(a)
1~100所有奇数的和
count=1
a=0
while count<100:
if count %2 ==1:
a=a+count
count += 1
print(a)
res=0
count=1
while count < 100:
if count%2 == 0:
res-=count
else:
res+=count
count+=1
print(res)
#6. 用户登陆(三次机会重试)
count = 3
while True:
if count>0:
name = input(‘please input your name:’)
pwd = input(‘please input your password:’)
if name==‘bob’ and pwd==‘11’:
print(‘login successful’)
break
else:
count -= 1
print(‘username or password error’,‘you can try :’,count)
count =3
while count > 0:
name = input(‘请输入用户名:’)
password = input(‘请输入密码:’)
if name==‘bob’ and password == ‘11’:
print(‘登陆成功’)
break
else:
print(‘用户名或密码错误’)
count -= 1
‘’‘教师版
count=0
while count < 3:
name=input(‘请输入用户名:’)
password=input(‘请输入密码:’)
if name == ‘egon’ and password == ‘123’:
print(‘login success’)
break
else:
print(‘用户名或者密码错误’)
count+=1’’’
#7:猜年龄游戏
示范2
tag=True
while tag:
name = input(‘please input youe name:’).strip() #去除字符串里的空白.strip
pwd = input(‘please input your password:’)
if name==‘egon’ and pwd==‘123’:
print(‘login success’)
while tag:
print(’’’
0 退款
1 取款
2 转账
3 查询
‘’’)
choice = input(‘请输入您要执行的操作:’) #choice=‘1’
if choice==‘0’:
tag=False
elif choice==‘1’:
print(‘取款》》》’)
elif choice==‘2’:
print(‘转账》》’)
elif choice == ‘3’:
print(‘查询》》》’)
else :
print(‘输入指令错误,请重新输入’)
else:
print(‘密码错误’)
for i in range(1, 10):
for j
# for j in range(1, 10):
x = i * j
print(’%s * %s = %s’ % (i, j, x), end=’’)
print()
for i in range(1,10):
for j in range(1,i+1):
print(’%s*%s=%s’ %(i,j,i*j)),#end=’ ')
print()
python创建提示用户输入查询条件_python流程控制练习相关推荐
- python创建提示用户输入查询条件_pythone-2:用户登录并根据条件查询
#!/usr/bin/env python #定义一个退出变量 EXIT="exit" #最大登录次数初值 num=1 #开始 while num < 4: num = nu ...
- 编写一个python程序判断用户输入的8位银行卡_用Python编写的程序,提示用户输入一个由7位数字组成的帐号?...
我在上一门Python入门课程,但有点困在作业上.任何建议或资源将不胜感激!在 问题是: 用Python编写一个程序,提示用户输入由7位数字组成的帐号.在 从用户处获取该帐号后,验证该帐号是否有效.您 ...
- python练习题:使用循环完成剪刀石头布游戏,提示用户输入要出的拳 :石头(1)/剪刀(2)/布(3)/退出(4)电脑随机出拳比较胜负,显示用户胜、负还是平局
""" 使用循环完成剪刀石头布游戏,提示用户输入要出的拳 :石头(1)/剪刀(2)/布(3)/退出(4) 电脑随机出拳比较胜负,显示用户胜.负还是平局.运行如下图所示:提 ...
- Pyhton基础篇(2)-变量、用户输入及条件语句(已更新)
1. 变量 Python中的变量概念很好理解,变量其实就是某个数值的"名字". 变量定义的规则: (1) 只能由数字.字母.下划线组成(不能以数字开头) (2) 不能使用关 ...
- python输入一组身高_一起学Python系列之用户输入
函数input(): 函数input() 让程序暂停运行, 等待用户输入一些文本. 获取用户输入后, Python将其存储在一个变量中, 以方便你使用. message=input("tel ...
- Java黑皮书课后题第8章:*8.31(几何:交点)编写一个方法,返回两条直线的交点。四个点存放在4*2的二维数组points中。编写一个程序,提示用户输入4个点,并显示交点
*8.31(几何:交点)编写一个方法,返回两条直线的交点.四个点存放在4*2的二维数组points中.编写一个程序,提示用户输入4个点,并显示交点 题目 题目描述 破题 代码 本题运行实例 题目 题目 ...
- Java黑皮书课后题第8章:**8.19(模式识别:四个连续相等的数)编写下面的方法,测试一个二维数组是否有四个连续相等的数字(水平、垂直、对角线方向都可以)。编写一个测试程序,提示用户输入一个数组
**8.19(模式识别:四个连续相等的数)编写下面的方法,测试一个二维数组是否有四个连续相等的数字(水平.垂直.对角线方向都可以).编写一个测试程序,提示用户输入一个数组 题目 题目描述与运行实例 破 ...
- Java黑皮书课后题第8章:**8.6(代数:两个矩阵相乘)编写两个矩阵相乘的方法。编写一个测试程序,提示用户输入两个3*3的矩阵,然后显示它们的乘积
**8.6(代数:两个矩阵相乘)编写两个矩阵相乘的方法.编写一个测试程序,提示用户输入两个3*3的矩阵,然后显示它们的乘积 题目 题目描述与运行示例 破题 代码 题目 题目描述与运行示例 **8.6( ...
- Java黑皮书课后题第5章:*5.14(计算最大公约数)下面是求两个整数n1和n2的最大公约数的程序清单5-9的另一种解法:...提示用户输入两个正整数,然后显示最大公约数
*5.14(计算最大公约数)下面是求两个整数n1和n2的最大公约数的程序清单5-9的另一种解法:首先找出n1和n2的最小值d,然后一次检验d.d-1.d-2....2.1,是否是n1和n2的公约数.第 ...
最新文章
- iOS UIbutton 点击无反应的几种情况
- 机器人3·15 | 赛迪「机器人国评中心」揭示机器人产品质量6大痛点!
- PostgreSQL索引页
- python读取所有txt文件_python如何批量读取txt文件
- linux查看端口所占用的进程号
- 二叉树先序遍历,中序遍历,后序遍历,层次遍历学习总结及完整C/C++代码
- java 图片不能正常移动_Java,我的图像不会更新/移动
- 换手机的等等!什么时候能用上1000元级5G手机?中国移动公布时间表
- Pychram - 使用介绍
- ijkplayer中遇到的问题汇总
- 如何打开oracle的回闪,oracle回闪操作
- 面试之springboot是什么?
- matlab求dfa指数,关于使用MF-DFA方法计算广义Hurst指数的MATLAB操作问题
- ccf练习题 F1方程式冠军
- python扩展包怎么安装_Python中扩展包的安装方法详解
- Livy的CDH环境parcel和csd制作
- 小程序中身份证号码认证简单的判断方法
- 【树莓派】树莓派3B+搭建Ubuntu
- python做工控机_「上位机软件」工控机上位机软件的开发历程(一) - seo实验室...
- 推荐几款目前最热门的前端框架
热门文章
- include和require区别
- 太极计算机ehr系统,(数据科学学习手札21)sklearn.datasets常用功能详解
- pandas尾部添加一条_Numpy与Pandas
- go语言 mysql卡死_一次mysql死锁的排查过程-Go语言中文社区
- 内网python 仓库_GitHub - xanarry/LanTrans-desktop: 这是一个用python写的局域网传文件工具, 跨平台, 仓库中还有安卓版的工程...
- mysql 检查记录存在_Mysql 插入记录时检查记录是否已经存在,存在则更新,不存在则插入记录SQL...
- 谷歌Chrome浏览器正式上新Android版黑暗模式
- 华硕主板如何u盘启动电脑
- js基础中Null、undefined、NaN、false、0、{}的理解及使用
- linux 串口信息记到日志,[linux学习笔记]之一:ubuntu ch340调试备忘