# i = 0
# while (i < 9):
# print("i ----> ",i)
# i = i + 1
# print(i,"i即将大于或者等于9,while不在执行")

#执行1-100的数字

# a1 = 1
# while a1 <= 100:
# print(a1,end=" ")
# a1 = a1 + 1

#执行100 -1 的数字
# a1 = 100
# while a1 >= 0:
# print(a1,end=" ")
# a1 = a1 - 1

#执行0+1+2+3+4+.....+100 的sum
# count = 0
# sum = 1
# while sum <= 100:
# count = count + sum #0+1+2+3
# sum += 1
# print(count)

#while 循环遍历列表内的值
# List = [1,2,3,4,5,6,7]
# items = len(List)
# count = 0 #表示索引的值
# while count < items:
# print("列表内的值------>:",List[count]) #每次打印索引值
# print("列表的索引的值------>",count)
# count += 1

#猜数字游戏
#1.猜无限次

# res = 999
# while True:
# guess_number = int(input("请输入要猜入的数字:"))
# if res == guess_number:
# print("猜对了,666")
# break #跳出循环,中止
# else:
# if guess_number > res:
# print("猜大了")
# else:
# print("猜小了")

#2.只能猜三次,自动停止程序
# res = 999
# times = 3
# while times > 0:
# guess_number = int(input("请输入要猜入的数字:"))
# if res == guess_number:
# print("猜对了,666")
# # break #跳出循环,中止
# continue #跳出当前循环
# else:
# if guess_number > res:
# print("猜大了")
# else:
# print("猜小了")
# times -= 1 # time = time -1

#3.猜三次,每次提示剩余的次数
# res = 999
# times = 3
# while times > 0:
# guess_number = int(input("请输入要猜入的数字:"))
# if res == guess_number:
# print("猜对了,666")
# if times != 0:
# print("您还剩" + str(times - 1) + "次机会")
# else:
# pass
# else:
# if guess_number > res:
# print("猜大了")
# if times != 0:
# print("您还剩" + str(times - 1) + "次机会")
# else:
# pass
# else:
# print("猜小了")
# if times != 0:
# print("您还剩" + str(times - 1) + "次机会")
# else:
# pass
# times -= 1 # time = time -1

#while 实现1-100以内的奇数,把结果存储在一个list中
# List = []
# i = 1
# while i < 100:
# if i % 2 != 0:
# List.append(i)
# i += 1
# print("新的列表:",List)

#while 语句,用户连续输入10个数字,求10个数字的平均值
List = []
times = 0
while times < 10:
num = int(input("请输入数字:"))
List.append(num)
print("您输入第" + str(times + 1)+"次数字")
times += 1
num1 = 0
for i in range(len(List)):
num1 += List[i]
print(num1/len(List))

#while计算偶数的和
n = 1
sum = 0
while n <= 100:
if n %2 == 0:
n += 1
continue
sum = sum + n
n += 1
print(sum)

#while 的break的实例
while True:
name = input("请输入:")
if name == "stop":
break
else:
print(name)

python基础之while语句操作的更多相关文章

  1. 第三章:Python基础の函数和文件操作实战

    本課主題 Set 集合和操作实战 函数介紹和操作实战 参数的深入介绍和操作实战 format 函数操作实战 lambda 表达式介绍 文件操作函数介紹和操作实战 本周作业 Set 集合和操作实战 Se ...

  2. Python基础之条件语句和循环

    条件语句 Python中的条件语句分为 if ...else . if ...elif...else  以及if ...else 的嵌套使用: username = input('请输入您的用户名:' ...

  3. Python基础(6) - 基本语句

    Python print(在Python 3.0中就变成了函数了) print语句是把对象用文本化的形式输出到标准的输出流上. Operation  Interpretation print spam ...

  4. Python基础入门-IF语句

    今天给大家分享一下Python中的IF语句的使用场景以及注意事项.主要内容如下: 1.python中的真假 2.Python操作符 3.if语句实例和嵌套实例 4.if语句中的if嵌套实例 5.and ...

  5. 【Python基础】条件语句

    Python条件语句是通过一条或多条语句的执行结果(True或者False)来决定执行的代码块. 可以通过下图来简单了解条件语句的执行过程: Python程序语言指定任何非0和非空(null)值为tr ...

  6. python基础之os模块操作

    # os模块 目录相关内置库import os# . 当前目录 .. 返回上一级目录# 1. os.path.abspath() --获取当前文件的绝对路径(不包含os模块.py) pwd# path ...

  7. python基础5(文件操作,with语句)

    打开文件 #使用 open f = open('路径',mode = '打开模式', encoding='编码') #可以使用with语句打开,不需要关闭,可以同时打开多个文件 with open(' ...

  8. Python基础7:文件操作

    [ 文件操作] 1 对文件操作流程 打开文件,得到文件句柄并赋值给一个变量 通过句柄对文件进行操作 关闭文件 现有文件如下: 昨夜寒蛩不住鸣. 惊回千里梦,已三更. 起来独自绕阶行. 人悄悄,帘外月胧 ...

  9. python学习笔记-(七)python基础--集合、文件操作&函数

    本节内容 1.集合操作 2.文件操作 3.字符编码与转码 4.函数操作 1.集合操作 集合是一个无序的.不重复的数据组合: 1.1 常用操作 它的作用是: 1)自动去重:列表变成集合,自动去重: &g ...

随机推荐

  1. MindSpore Lite整体架构介绍

    MindSpore Lite整体架构介绍 MindSpore Lite框架的总体架构如下所示: 前端(Frontend): 负责模型生成,用户可以通过模型构建接口构建模型,将第三方模型和MindSpo ...

  2. VTA:深度学习加速器堆栈

    VTA:深度学习加速器堆栈 多功能Tensor加速器(VTA)是一个开放的,通用的,可定制的深度学习加速器,具有完整的基于TVM的编译器堆栈.设计VTA来展示主流深度学习加速器的最显着和共同的特征.T ...

  3. 多尺度目标检测 Multiscale Object Detection

    多尺度目标检测 Multiscale Object Detection 我们在输入图像的每个像素上生成多个锚框.这些定位框用于对输入图像的不同区域进行采样.但是,如果锚定框是以图像的每个像素为中心生成 ...

  4. 开发平台支持Arm Cortex-M的微控制器上人工智能训练

    开发平台支持Arm Cortex-M的微控制器上人工智能训练 Development platform enables AI training on Arm Cortex-M-based microc ...

  5. python接口自动化之读取excel表的数据(使用openpyxl模块)

    1.安装openpyxl:pip install openpyxl 2.基础知识,直接上代码 import openpyxl #导入模块 wd2=openpyxl.load_workbook('stu ...

  6. Java Object类中toString方法的重写

    Object类中的tostring方法的: 当我们输出一个对象时,实际是输出的是这个类中的tostring方法,是一个地址值,而不是类中的属性. 1 一:子类没有重写Object类中的toStrinn ...

  7. 开源FastGithub

    0 前言 github网站访问慢或访问不了,相信很多人都会遇到过,解决方式大概有两种:一种是使用代理访问:另一种是使用ipaddress.com等域名解析网站查询域名的ip,然后在host文件增加ip ...

  8. js 统计图插件chart.js

    chart是一个纯js插件,它功能强大小巧使用也很简单. 第一步引入 chart.js . <script type="text/javascript" src=" ...

  9. 最好的Kubernetes客户端Java库fabric8io,快来自定义你的操作

    我最新最全的文章都在南瓜慢说 www.pkslow.com,欢迎大家来喝茶! 1 Kubernetes Java客户端 对于Kubernetes集群的操作,官方提供了命令行工具kubectl,这也是我 ...

  10. spring中BeanPostProcessor之四:AutowiredAnnotationBeanPostProcessor(01)

    在<spring中BeanPostProcessor之二:CommonAnnotationBeanPostProcessor(01)>中分析了CommonAnnotationBeanPos ...