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的更多相关文章
随机推荐
- 正在从 Windows 应用商店下载... 无法从 Windows 应用商店下载。请检查网络连接。
手贱关掉了一下服务,再打开就是嘛
- Stm32CubeMX5 配置 外部中断
实验使用连接PA8引脚的按键触发中断,外部中断使用双边沿触发,这样就可以检测按键按下与松开,当按键按下时点亮LED, 当按键松开是关闭LED,在中断服务函数中只置位相应的标志,在main函数中具体处理 ...
- tomcat的首次登录配置
登录tomcat时需要输入账号密码,而账号密码需要在配置文件中配置好才能使用. 此处我们先点击取消,tomcat会弹出一个提示界面: 这个界面的大致意思是: 401未经授权 您无权查看此页面. 如果您 ...
- dill:解决python的“AttributeError: Can't pickle local object”及无法pickle lambda函数的问题
python的pickle是用来序列化对象很方便的工具,但是pickle对传入对象的要求是不能是内部类,也不能是lambda函数. 比如尝试pickle这个内部类: 结果会报错AttributeErr ...
- Postfix+Dovecot+MySQL搭建邮件服务器
网上有很多使用Postfix搭建邮件服务器的文章,但目前貌似没有看到较为完整的一篇.本例将尝试在Ubuntu系统中使用Postfix+Dovecot+MySQL搭建邮件服务器. 说到邮件服务器,网上有 ...
- qdatatime大小
QDateTime time1; QDateTime time2; uint stime = time1.toTime_t(); uint etime = time2.toTime_t(); int ...
- 2017 ACM/ICPC Asia Regional Shenyang Online 12 card card card
题目大意: 给出两个长度为n的序列A,B,从1开始依次加Ai,减Bi,分数为第一次为当前和为负数的位置以前的Ai之和(左闭右开区间).同时有一种操作可以把当前的A1,B1移动到序列最后,注意序列A的各 ...
- fastDFS配置文件 fdfs_client.conf
# connect timeout in seconds# default value is 30sconnect_timeout=30 # network timeout in seconds# d ...
- 【LeetCode 2】两数相加
描述 [题解] 模拟高精度的加法. 用x来记录前面的进位就好. [代码] /** * Definition for singly-linked list. * struct ListNode { * ...
- Android中ViewPgae中的Fragment如何确认当前页面可见的问题
由于在ViewPage中PageAdapter来管理所有的Fragment.在加载一个Fragment的时候,会自动缓存左右几个(默认是一个)页面,此时也会调用到正常的生命周期函数,onCreate, ...