分支结构

简单的使用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. .net core 序列日志Serilog

    Serilog 是一个用于 .NET 应用程序的诊断日志库.它易于设置,具有干净的 API,并且可以在所有最新的 .NET 平台上运行.尽管即使在最简单的应用程序中它也很有用,但 Serilog 对结 ...

  2. 如何添加Eclipse项目到SVN资源库

    Eclipse项目添加到SVN版资源库有如下好处:一是轻松备份,每天做的修改内容一键提交:二方便合作,比较大的项目,多个人一起工作的时候,每人及时将完成的代码提交,别人可以下载浏览:三展示项目完成进度 ...

  3. 组件中的data为什么不是一个对象而是一个函数?

    组件中的data为什么不是一个对象而是一个函数? 组件是可复用的vue实例,一个组件被创建好之后,就可能被用在各个地方,而组件不管被复用了多少次,组件中的data数据都应该是相互隔离,互不影响的,基于 ...

  4. ubuntu20.04开机自动运行脚本实例

    在 Ubuntu 20.04 中,/etc/rc.local 文件仍然存在,但不再默认启用,因为它已经被 systemd 代替.下面是使用systemd开机执行的脚本的实例: 1.编写脚本myscri ...

  5. 由于CVE-2020-10770漏洞,k8s集群升级keycloak 8.0.0-->15.0.0(由于15.0.0最近又出安全漏洞,升级为16.0.0)

    背景 前段时间项目组用到的8.0.0版本的keycloak被安全部门同事扫出来一个中危漏洞: A flaw was found in Keycloak, where it is possible to ...

  6. vs code 提交代码弹框提示:请确保已在git中配置您的“user.name”和“user.email” ——解决方法

    修改完项目代码,准备提交到git上,结果提交失败,弹框提示:请确保已在Git中配置您的"user.name"和"user.email" 打开终端,配置运行一下命 ...

  7. 日記かな、自分のサーバ作りの?(01、try…catch…の問題)

    今日まだ終わらないうちに.昼間から出会ったbugについて.取りまとめましょう. 一応try-catch-にかかわる問題かな- try(do something){ }catch{ } と try(){ ...

  8. 读后笔记 -- Java核心技术(第11版 卷 II) Chapter3 XML

    3.1 XML Introduction An XML document is made up of elements. An element can have attributes (key/val ...

  9. Cleanest XMaster绿色解压最新版下载9.6密钥激活码

    cad安装报错换了好几个版本都不行,用这个卸载了一下,确实有用 Cleanest XMaster绿色版cad卸载工具分享下载 地址一(百度网盘) 地址二(直接下载) 9.6.05密钥:[AtrXShX ...

  10. C++ 用同一个raw pointer传入shared_ptr构造函数生成两个智能指针有什么问题?

    Effective Modern C++ Item 19: use std::shared_ptr for shared-ownership resource Now, the constructor ...