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')

  

转载于:https://www.cnblogs.com/Y139147/p/11278836.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ARIMA算法是一种时间序列预测模型,可以通过对历史数据进行分析和预测来检测异常。下面是使用Python实现ARIMA算法进行异常检测的步骤: 1. 导入必要的库: ```python import pandas as pd import numpy as np import matplotlib.pyplot as plt from statsmodels.tsa.arima_model import ARIMA ``` 2. 加载数据并进行预处理: ```python # 加载数据 data = pd.read_csv('data.csv', header=None) # 转换为时间序列 ts = pd.Series(data[1].values, index=pd.to_datetime(data[0], unit='s')) ``` 3. 绘制时间序列图来观察数据: ```python plt.plot(ts) plt.show() ``` 4. 对时间序列进行差分,以便于进行平稳性检验: ```python diff_1 = ts.diff(1).dropna() plt.plot(diff_1) plt.show() ``` 5. 进行平稳性检验: ```python from statsmodels.tsa.stattools import adfuller def test_stationarity(timeseries): # Dickey-Fuller test: result = adfuller(timeseries) print('ADF Statistic: %f' % result[0]) print('p-value: %f' % result[1]) print('Critical Values:') for key, value in result[4].items(): print('\t%s: %.3f' % (key, value)) test_stationarity(diff_1) ``` 如果p-value小于0.05,则认为时间序列是平稳的。 6. 构建ARIMA模型并训练: ```python model = ARIMA(ts, order=(1, 1, 1)) results_ARIMA = model.fit(disp=-1) ``` 7. 预测并绘制预测结果: ```python pred = results_ARIMA.predict(start='2019-08-01', end='2019-08-31', dynamic=True) plt.plot(ts) plt.plot(pred, color='red') plt.show() ``` 8. 计算预测误差并进行异常检测: ```python residuals = ts - pred mean = np.mean(residuals) std = np.std(residuals) threshold = mean + 3*std anomalies = [i for i in range(len(residuals)) if (residuals[i] > threshold or residuals[i] < -threshold)] print('Anomalies:', anomalies) ``` 以上就是使用Python实现ARIMA算法进行异常检测的步骤。需要注意的是,ARIMA算法需要时间序列数据满足平稳性才能进行预测,因此需要对数据进行预处理。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值