2019_7_31python
练习 输入三条边长如果能构成三角形就计算周长和面积
import math
a,b,c = input().split(',')
a = float(a)
b = float(b)
c = float(c)
if a + b > c and a + c > b and b + c > a:
print('周长%f'%(a + b + c))
p = (a + b + c)/2 area = math.sqrt( p * ( p - a ) * ( p - b )*( p - c ))
print('面积%f'%(area))
else:
print('不能构成三角形')
练习 求平均值
flag = 0
sum = 0
while 1:
print('Enter an integer, the input ends if it is 0: ')
shu = input()
if shu != '0' :
sum = sum + float(shu)
flag +=1
else:
break
ave = float(sum/flag)
print('平均值是%f' %ave)
练习 个人所得税计算器
salary = float(input('本月收入: '))
insurance = float(input('五险一金: '))
diff = salary - insurance - 3500
if diff <= 0:
rate = 0
deduction = 0
elif diff < 1500:
rate = 0.03
deduction = 0
elif diff < 4500:
rate = 0.1
deduction = 105
elif diff < 9000:
rate = 0.2
deduction = 555
elif diff < 35000:
rate = 0.25
deduction = 1005
elif diff < 55000:
rate = 0.3
deduction = 2755
elif diff < 80000:
rate = 0.35
deduction = 5505
else:
rate = 0.45
deduction = 13505
tax = abs(diff * rate - deduction)
print('个人所得税: ¥%.2f元' % tax)
print('实际到手收入: ¥%.2f元' % (diff + 3500 - tax))
生成随机验证码
验证码
import random
import numpy as np
import string
print('开始生成验证码')
s = string.ascii_lowercase
str1 = ""
for i in range (3):
for i in range(0,4):
a = random.choice(s)
b = np.random.choice([1,2,3,4,5,6,7,8,9,0])
c = random.choice([a,b])
print(c,end="")
str1 = str(str1)+str(c)
print('')
shuru = input('请输入验证码')
if shuru == str1 :
print('成功')
break
else:
print('再试一次')
密码爆破
import itertools
username = 'admin'
print('输入一个6位以内纯数字密码')
password = int(input())
print('开始爆破')
for i in range (0,999999):
print(i)
if int(i) == password:
print('爆破成功,密码%s' %i)
break
else:
continue
石头剪子布
import numpy as np
res = np.random.choice(['0','1','2'])
x=input('输入0、剪刀 1、石头 2、布')
if res=='0':
if x=='0':
print("tie")
elif x=='1':
print('loser')
else:
print('win')
elif res=='1':
if x=='2':
print("win")
elif x=='0':
print('tie')
else:
print('loser')
else:
if x=='2':
print("loser")
elif x=='1':
print('win')
else:
print('tie')
2019_7_31python的更多相关文章
随机推荐
- The Accomodation of Students HDU - 2444 二分图判定 + 二分图最大匹配 即二分图-安排房间
/*655.二分图-安排房间 (10分)C时间限制:3000 毫秒 | C内存限制:3000 Kb题目内容: 有一群学生,他们之间有的认识有的不认识.现在要求把学生分成2组,其中同一个组的人相互不认 ...
- a number of 和the number of用法
a number of 和the number of用法 1. A number of + 複數名詞 + 複數動詞 =some/或a lot of + 複數名詞 + 複數動詞 ...
- Guava之controller中使用缓存cache
之前介绍过的Guava这个工具包中有很多方便的用法,下面要使用它封装的Cache来实现功能. 示例: import com.google.common.cache.CacheBuilder; impo ...
- android中的Serveice组件
创建 配置 Service: 1.定义一个继承了Service类的子类 2.在 AndroidManifest.xml清单文件中对开发的Service进行配置 Service和Activity很相似, ...
- shell变量替换扩展 字符串计数截取
- 【CSS】div的背景图完整图片覆盖
最初的代码: .container_first { width: 100%; height: 100%; background: url(10176581.jpg); background-size: ...
- spring启动异步线程
大纲: spring启动异步线程 spring配置线程池 一.spring启动异步线程 spring启动异步线程方法就是在方法上加上注解@Async,然后启动类或配置类上加上注解@EnableAsyn ...
- IntelliJ IDEA下载地址
http://www.jetbrains.org/display/IJOS/Download
- Andrdoid中对应用程序的行为拦截实现方式之----从底层C进行拦截
之前的一篇概要文章中主要说了我这次研究的一些具体情况,这里就不在多说了,但是这里还需要指出的是,感谢一下三位大神愿意分享的知识(在我看来,懂得分享和细致的人才算是大神,不一定是技术牛奥~~) 第一篇: ...
- 出现Warning: date(): It is not safe to rely on the system's timezone settings的解决办法
在没有配置,尤其是新安装的PHP中使用date函数时,会报这个错误: Warning: date(): It is not safe to rely on the system's timezone ...