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 ...
随机推荐
- StarRC 转XRC flow
抽取寄生参数是我们工作中经常做的事情,目前来说三家EDA 都有抽取工具,分别是StarRC, XRC,QRC,其中QRC现在有个升级版本Quantus,但是由于calibre在DRC 和LVS方面太强 ...
- 一条命令删除所有静态路由华为eNSP
在系统视图下执行undo ip route-static all,可以一次删除所有静态路由,包括缺省路由. 默认状态: 执行 undo ip route-static all
- 前端之Vue day08 Vue3项目搭建、setup、toRefs
一.Vue3 介绍 # 新项目使用vue3,有部分老项目使用vue2 # vue3 的变化 1.性能的提升 -打包大小减少41% -初次渲染快55%, 更新渲染快133% -内存减少54% 2.源码的 ...
- 报错解决OSError: /lib64/libm.so.6: version `GLIBC_2.27' not found
使用pyg报错如下: 1 Traceback (most recent call last): 2 File "main.py", line 18, in <module&g ...
- const char* str和const char str[]的区别
首先,字符串常量是存储在flash中的.假设字符串常量在flash中的地址是0x8003fb8. 第一种方式,str等价于str的内存单元的地址,str的内存单元存储着字符串常量的地址 第二种方式,s ...
- SQL语句大全,你不会写的SQL可能都在这里
1.创建数据库 CREATE DATABASE database-name 2.删除数据库 drop database dbname3.说明:备份sql server 创建 备份数据的 device ...
- 【Asp.net】服务器控件<asp:TextBox ></TextBox>如何变为多文本控件
废话不多说,直接上图! 在TextBox上增加TextModel="MultiLine"即可!
- Jmeter 请求或响应中文乱码
1.首先检查 请求编码和后台接受编码是否一致,如果在查看结果树中 请求的中文不是乱码 而添加到后台程序是乱码 一般都是请求和接受编码不一致造成的 2.如果请求是get 请求中有中文 Content e ...
- element3 form表单校验对象里面有对象的情况
let formSearch = reactive({ queryParam: [ { field: "", //查询的字段 gzcs: "", //规则参数 ...
- ubuntu22.04LTS下编译glfw
环境准备 # 预装cmake sudo apt install cmake # 下载源码 git clone https://github.com/glfw/glfw.git 编译 # cmake初始 ...