分支结构

简单的使用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的更多相关文章

  1. 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 ...

  2. RSA Study

    These days I study the RSA Algorithm. It is a little complex, but not very. Also, my study has not f ...

  3. Machine Learning Algorithms Study Notes(3)--Learning Theory

    Machine Learning Algorithms Study Notes 高雪松 @雪松Cedro Microsoft MVP 本系列文章是Andrew Ng 在斯坦福的机器学习课程 CS 22 ...

  4. Machine Learning Algorithms Study Notes(2)--Supervised Learning

    Machine Learning Algorithms Study Notes 高雪松 @雪松Cedro Microsoft MVP 本系列文章是Andrew Ng 在斯坦福的机器学习课程 CS 22 ...

  5. Machine Learning Algorithms Study Notes(1)--Introduction

    Machine Learning Algorithms Study Notes 高雪松 @雪松Cedro Microsoft MVP 目 录 1    Introduction    1 1.1    ...

  6. 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 ...

  7. 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 ...

  8. A Study of WebRTC Security

    转自:http://webrtc-security.github.io/ A Study of WebRTC Security Abstract Web Real-Time Communication ...

  9. study topics

    永远不变的东西,原理 study roadmap: 1.user space: tizen power manager => suspend/resume or runtime? android ...

  10. 读书笔记2013第10本:《学得少却考得好Learn More Study Less》

    <学得少却考得好Learn More Study Less>这本书最早是从褪墨网站上看到的,crowncheng翻译了全文.这本书介绍了不少学习方法,非常适合在校的学生,原文的作者Scot ...

随机推荐

  1. git仓库搭建及免密使用

  2. 13.java栈实现计算器

    更新了代码,能跑通了,昨天果然是太晚了脑子混了,今天一看其实就差一句,在最后while循环的时候忘记把拿到的oper从栈里pop出去了,导致oper栈一直不空就要一直从数据栈中取数据进行计算所以一直在 ...

  3. 通过一个简单的实例来展示 Java 编程,创建文件 HelloWorld.java

    public class HelloWorld { public static void main(String[] args) { System.out.println("Hello Wo ...

  4. 剑指 Offer 栈与队列

    09. 用两个栈实现队列 没啥意思 不要想复杂了 就是暴力 class CQueue { public: CQueue() { } /* 一个主栈 一个缓存栈 来回导 得到队头 copy后一端变空了 ...

  5. js函数参数默认值

    以前的写法,利用短路原则来写: function haosy(name,age){ name=name||'小郝'; age=age||21; alert('读者你好,我是作者'+name+',芳龄' ...

  6. 小程序调用OCR识别操作的过程,特此记录。

    bu废话,直接记录.(注:我用的是云调用!!!) 对于大家首次使用该操作时,推荐两位大佬的文章,大家完全可以看两位大佬的文章,一步一步来就可以实现. 第一个文章呢,先看这个 https://blog. ...

  7. docker的安装和命令

    一. 认识Docker 我们写的代码会接触好几个环境:开发环境,测试环境以及生产环境 开发环境:程序员开发代码的环境 测试环境:开发完的代码部署到测试环境 给测试人员进行测试 生产环境:测试完成后有运 ...

  8. 【阿里云ACP】-02(弹性储存、对象储存OSS)

    弹性网卡 弹性网卡: 是一种可以附加到专有网络VPC类型ECS实例上的虚拟网卡.通过弹性网卡,您可以在任何阿里云地域下实现高可用集群搭建.低成本故障转移和精细化的网络管理. 弹性网卡属性: 属性 规格 ...

  9. JavaScript的知识点整理

    最近写了一个员工管理作业,暴露了一些问题就是. JS的查找标签的时候,要确定返回的是DOM对象还是数组,document对象可以是任意dom对象,将查询范围限制在当前dom对象, 1.直接查找标签 d ...

  10. 思科IPsecVPN建立

    实验拓扑 实验目标: 1.不配置中间的三个路由器的路由实现router0和router2的vpn隧道 2.PC0能够ping通PC1 实验IP预定: PC0 10.1.1.1/24 PC1 20.1. ...