python中用break结束死循环
Python 结束 break 中用 死循环
2023-09-14 09:05:39 时间
while True:
s=input('请输入>>>')
if s=='quit()':
break
print('你刚输入的是',s)
print('程序结束')
j=1
while j<=5:
i=1
while i<=8:
print(i)
if i==4:
break
i+=1
j+=1
执行结果
1
2
3
4
1
2
3
4
1
2
3
4
1
2
3
4
1
2
3
4
练习:任意输入一些正整数,当输入负数时结束输入
当输入完成后,打印你刚输入这些数的和
习题答案
data=0
while True:
x=int(input('请输入数'))
if x<=0:
print(data)
break
data+=x
习题 输入一个整数n打印一个宽度为n个字符宽度的正方型
x=int(input())
i=1
alf='*'
while i<=x:
j=1
while j<=x:
if i==1 or i==x:
print(alf,end=' ')
elif i!=1 or i!=x:
if j==1 or j==x:
print(alf,end=' ')
if j!=1 and j!=x:
print(' ',end=' ')
j+=1
print()
i+=1
输出结果
8
练习:求下列多项式的和
1+1/2+1/4+1/8.。。。。。1/2**1000的和
写程序求1-1/3+1/5-1/7+1/9+...........1/(2*n-1)
求n=10000时此公式的和
将上面结果×4打印
用while语句实现打印等腰直角三角型输入的数为直角边
习题答案
x=int(input())
i=1
num=0
while i<=x:
num+=1/2**(i-1)
i+=1
else:
print(num)
x=int(input())
num=0
i=1
while i<=x:
num+=(1/(2*i-1))*((-1)**(i+1))
i+=1
print(num)
print(4*num)
x=int(input())
i=1
while i<=x:
print(i*'* ',end='')
print()
i+=1
相关文章
- 8 月编程语言排行榜:没有一门语言能比得上 Python
- aic准则python_Python数据科学:线性回归
- python的进制转换器,Python进制转换[通俗易懂]
- Python 敏感词过滤的实现「建议收藏」
- python海龟绘图画圆_Python启蒙之海龟作图「建议收藏」
- python进阶(15)多线程与多进程效率测试[通俗易懂]
- Python抓取数据_python抓取游戏数据
- lua sort排序_python中列表排序的用法
- python setattr函数_Python内置函数(53)——setattr
- 【说站】python中findall()和finditer()的区别
- 【说站】python Task如何在协程调用
- Python保存json_python保存json文件
- python里面的缩进是什么意思_Python缩进规则(一看即懂)[通俗易懂]
- win10怎么安装python3.8_win10怎么安装python
- python type error是什么意思_Python 报错 TypeError:’DoesNotExist’对象不可调用
- Python应该要会一点吧
- Python接口自动化测试自学路线
- KG4Py:Python代码知识图谱和语义搜索的工具包
- 【测试开发】python系列教程:Python数据类型转换
- 【测试开发】python系列教程:Python 推导式
- PYTHON银行机器学习:回归、随机森林、KNN近邻、决策树、高斯朴素贝叶斯、支持向量机SVM分析营销活动数据|数据分享|附代码数据
- 基于UIAutomation+Python+Unittest+Beautifulreport的WindowsGUI自动化测试框架主入口main解析
- Python计算woe及应用
- python-Python与SQLite数据库-SQLite数据库的基本知识(一)
- python-Python与SQLite数据库-使用Python执行SQLite查询(一)
- python-Python与SQLite数据库-处理SQLite查询结果(二)
- python通过openpyxl生成Excel文件详解编程语言
- Python计算两个日期之间的相差的秒数详解编程语言
- 用Python简化Linux指令:从繁琐变简单(python运行linux命令)
- MySQL与Python搭配,实现数据库操作。(mysql-python)
- Linux与Python:开拓者的新时代(linux和python)
- 掌握Linux环境下的Python编程(linux执行python)
- Python与MySQL实现数据分析的完美组合(mysql中python)
- Python模拟登录12306的方法
- 跟老齐学Python之玩转字符串(1)