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 ...
随机推荐
- windows下搭建stm8s开发环境
拓扑:windows -> st_link_v2 ->目标板,目标板不由st_link_v2供电 接线: st_link_v2: NRST GND SWIM 3V3 ↓ ↓ ↓ ↓ 目标板 ...
- Linux学习 --- 系统网络配置
前言 : 如果一台计算机想接入互联网,必须配置好IP地址,子网掩码,网关,DNS服务器.在Linux系统中,这些信息都可以修改对应的配置文件来进行配置.临时配置一下网络可以使用一些简单的命令来进行配置 ...
- Java多线程编程技术方案原理
一 ,多线程相关的一些概念 1,线程和进程: 线程指的是进程中一个单一顺序的控制流, 进程中可以并发多个线程,每条线程并行执行不同的任务,被认为是一个计算资源的集合.进程不能被任务是一个应用,因为有些 ...
- Git相关、Gitee多人协同开发
Git相关 1.介绍 是一个具有版本控制的软件,控制开发的项目代码,具有集群化.多分支的功能 2.对于程序员的作用 协同开发 解决代码合并过程中冲突 代码版本管理 3.git 与 svn 比较 ...
- vue中require动态加载图片
<template> <img src="D:/images/01.png" alt="静态加载"> <img :src=&quo ...
- 2023-03-03 js map 双重嵌套
恩..其实也没啥要记录的,记住关键一点就是必须要有return,不管是几重,比如: arr.map((item, index) => { return ( item.ar ...
- Mysql 无法使用注释 带注释执行报错 Dbeaver
一.场景 执行时,前面带一段注释,在dbeaver执行报语法错误 二.解决办法 在注释后面插入一个空格,识别注释后变成灰色,执行成功
- Docker学习笔记-01 初步了解
1. 理念:将应用打成镜像,通过镜像成为运行在Docker容器上面的实例,而 Docker容器在任何操作系统上都是一致的,这就实现了跨平台.跨服务器.只需要一次配置好环境,换到别的机子上就可以一键部署 ...
- es 集群并设置密码
1. 生成证书 bin/elasticsearch-certutil cert -out config/elastic-certificates.p12 -pass ""2. el ...
- C# DateTime转换为字符串
12小时制:DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") 24小时制:DateTime.Now.ToString("yyyy- ...