Study python_02
分支结构
简单的使用if语句
使用if-else
import random
# 调用一个随机数包(只看if的情况可忽略)
n1 = random.randrange(100)
n2 = random.randrange(100)
print(n1,n2)
jg = int(input())
if jg == (n1 + n2):
print('结果为真')
else:
print('结果为假')
简单的使用if语句
使用if-elif-else
a,b,c = map(float,input("Enter a,b,c : ").split())# 连续输入三个数字
i = b * b - (4 * a * c)
if i >0 :
r1 = (-b + (b * b - (4 * a * c))** 0.5) / 2 * a
r2 = (-b - (b * b - (4 * a * c))** 0.5) / 2 * a
print("The roots are {} and {}",r1,r2)
elif i == 0 :# 使用elif再次判断
print(-b / 2 * a)
else :# 使用else进行最后的输出
print("The equation has no real roots")
循环结构
简单的使用for语句
password = input('passward:')# 输入一串字符,必须包括数字,大小写字母
count1,count2,count3 = False,False,False
for i in password:# 从第一个字母开始判断
if i <= 'Z' and i >='A':
count1 = True
if i <= 'z' and i >='a':
count2 = True
if i <= '9' and i >='0':
count3 = True
if count1 and count2 and count3:
print('ok')
else:
print('必须包含大小写和数字')
简单的使用while语句
i = 0
while i<10:
print('我是大牛')
i += 1
使用break
import random
c = random.randrange(1000,9999)
print('验证码:',c)
for i in range(3):
b = int(input('请输入验证码:'))# 结果不要应该有四次输出,懒得改
if b == c:
print('输入正确')
break
else:
print('输入错误,请重试')
else:
print('请退出账号重试')
有点头疼的for和if-elif
import numpy as np
A = '石头'
B = '剪刀'
C = '布'
for i in range(6):# 循环6次
res = np.random.choice([A,B,C])
res1 = np.random.choice([A,B,C])
print('电脑出的:',res,'你出的',res1)
if (res == A) and (res1 == B):
print('你输了')
elif (res == A) and (res1 == C):
print('你赢了')
elif (res == B) and (res1 == C):
print('你输了')
elif (res == B) and (res1 == A):
print('你赢了')
elif (res == C) and (res1 == A):
print('你输了')
elif (res == C) and (res1 == B):
print('你赢了')
elif (res == A) and (res1 == A):
print('平局')
elif (res == B) and (res1 == B):
print('平局')
elif (res == C) and (res1 == C):
print('平局')
Study python_02的更多相关文章
- Improve Your Study Habits
1.Plan your time carefully. Make a list of your weekly tasks.Then make a schedule or chart of your t ...
- RSA Study
These days I study the RSA Algorithm. It is a little complex, but not very. Also, my study has not f ...
- Machine Learning Algorithms Study Notes(3)--Learning Theory
Machine Learning Algorithms Study Notes 高雪松 @雪松Cedro Microsoft MVP 本系列文章是Andrew Ng 在斯坦福的机器学习课程 CS 22 ...
- Machine Learning Algorithms Study Notes(2)--Supervised Learning
Machine Learning Algorithms Study Notes 高雪松 @雪松Cedro Microsoft MVP 本系列文章是Andrew Ng 在斯坦福的机器学习课程 CS 22 ...
- Machine Learning Algorithms Study Notes(1)--Introduction
Machine Learning Algorithms Study Notes 高雪松 @雪松Cedro Microsoft MVP 目 录 1 Introduction 1 1.1 ...
- jar tvf study.war jar命令查看war/jar包的内容
jar tvf study.war 0 Thu Oct 20 14:01:18 CST 2016 META-INF/ 137 Thu Oct 20 14:01:16 CST 2016 META-INF ...
- Mongo DB Study: first face with mongo DB
Mongo DB Study: first face with mongo DB 1. study methods: 1. Translate: I am the mongo DB organiz ...
- A Study of WebRTC Security
转自:http://webrtc-security.github.io/ A Study of WebRTC Security Abstract Web Real-Time Communication ...
- study topics
永远不变的东西,原理 study roadmap: 1.user space: tizen power manager => suspend/resume or runtime? android ...
- 读书笔记2013第10本:《学得少却考得好Learn More Study Less》
<学得少却考得好Learn More Study Less>这本书最早是从褪墨网站上看到的,crowncheng翻译了全文.这本书介绍了不少学习方法,非常适合在校的学生,原文的作者Scot ...
随机推荐
- win10 + emacs + sml
1.官网下载sml编译器是smi安装包,安装结束之后把bin文件夹放到环境变量Path中 2.下载emacs压缩包,直接解压 3.emacs中alt+x,输入package-list 然后选择sml- ...
- C语言II博客作业04
C语言II-作业04 作业头 这个作业属于哪个课程 https://edu.cnblogs.com/campus/zswxy/SE2020-2/?page=2 这个作业要求在哪里 https://ed ...
- python对文件的处理方法
#1.打开文件 如果文件不存在会报错 file = open("1.txt") #2.使用w.w+.a.a+模式打开,如果文件不存在就创建文件 file = open(" ...
- SQL注入之延时注入(10)
以下提供两种方式进行延时注入 GET /sqli/Less-10/?id=1"+and+sleep(5)--+ HTTP/1.1 Host: 192.168.245.146:6101 Use ...
- 【Hive 元数据和真实数据-TAB_COL_STATS记录错误问题】
MySql的元数据以及HDFS上数据的关系 元数据在DBS和TBLS上 (SD_ID) 1 首先通过hive创建一个表table_test 在hdfs的存储路径会生成相应的表 TBLS 也会更新内容进 ...
- jmeter使用Java请求二
继承 AbstractJavaSamplerClient类来实现jar编辑 来写jmeter测试脚本 将如下两个包引入Java项目: ApacheJMeter_core.jar ApacheJMete ...
- Flink 消费RabbitMQ 和 Kafka
在消息RabbitMQ时,我们关心的一个问题是手动ack还是自动ack,如果是自动ack就怕出现丢消息的情况 Flink以RabbitMQ作为Source,是怎么保证消息唯一性的呢,是怎么保证ack的 ...
- File.createTempFile()
File.createTempFile()的两个参数,是前缀和后缀,临时文件的文件名,会在前缀和后缀中各截取一部分,再拼接上随机数进行生成: 推荐手动指定目录,尽量指定到项目路径下,默认的磁盘位置,有 ...
- 解决QtCreator运行程序报plugin xcb的错误
解决方法:将对应项目的运行环境的LD_LIBRARY_PATH中的qt的库路径移到最前面,如下图: LD_LIBRARY_PATH可以指定查找共享库的路径,将qt的共享库移到前面,可以优先使用qt的库
- Redis 突然变慢了如何排查并解决?
业务场景 某购物平台打算举行"双十一"大型购物狂欢活动,到了半夜12点用户数量暴增,出现了一个技术故障,用户发现自己无法下单!!! 技术组立即组织人手进行故障排查,结论是 Redi ...