分支结构

简单的使用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. 小白之Python-基础中的基础03

    序列,目前看来很基础,东西比较多,难度开始加大...加油吧,骚年 Python之序列 1.数据结构:序列.容器(序列:索引.映射:键).集合2.列表.元组.字符串.Unicode字符串.buffer对 ...

  2. mysql 优化表空间报错Creating index 'PRIMARY' required more than 'innodb_online_alter_log_max_size' bytes of modification log. Please try again

    背景:mysql数据库中有几个表的碎片率太高,浪费了存储空间且降低了读写效率,需要整理. mysql版本:5.6 先用optimize table 试试. 也执行了很久.但是结束后,data_free ...

  3. params的使用

    今天在写vue的JavaScript的时候有个地方需要传很多参数,自己写不出来,求助 我的博博 后拿到神奇代码: 神奇代码中有params,俺自作聪明,以为他是一个json的数据,所以自己改了个名字 ...

  4. pillow 创建图片并添加一些自定义信息

    from PIL import Image vm = Image.new('RGBA', (dshape[1], dshape[0])) vm = Image.fromarray(np.array(s ...

  5. 批量修改excel中超链接

    打开需要处理的excel文件 alt + F11打开VB编辑器 双击打开对应的sheet 编辑如下代码 Dim oldfile As String Dim Newfile As String Sub ...

  6. 关于之前ecplices没法正常导入使用fx包的笔记

    办法一:在java build path里的libraries里导入跟工作环境版本(或者ecplices的jdk版本)相配的jar包. 注:如果导入的包是要用fx的,可以不直接改整个程序的工作环境,可 ...

  7. UML各种图实践题

    1. 用状态图描述一部电梯的运行

  8. Respecting causality is all you need for training physics-informed neural networks

    未发表 本篇工作时关于连续时间的PDE.也是从因果关系的角度入手,最近看过几篇该作者的工作.(简而言之就是从初始条件方向开始训练) 目前的PINN框架缺乏尊重物理系统演化所固有的时空因果结构.因此,作 ...

  9. docker的生命周期

    所有博客仅用于自己学习记录,如有侵权请联系删除,文章来源于公开视频资料,如有需要请移步这里:https://www.bilibili.com/video/BV1o14y1w7b8?p=11&v ...

  10. 连接Oracle 19c出现ORA-28040:没有匹配的验证协议

    错误信息:ORA-28040:没有匹配的验证协议处理方法 出现这个原因是因为你的Oracle连接客户端与服务端Oracle的版本不匹配造成的.一般是低版本客户端连接高版本服务端出现. 高版本连接低版本 ...