当前位置:网站首页>Have a look at this generation
Have a look at this generation
2022-07-06 02:02:00 【Wild universe PY】
input data
def getNum():
nums = []
iNumStr = input('please input a sequence of numbers (enter to exit): ')
while iNumStr != ‘’:
nums.append(eval(iNumStr))
iNumStr = input('please input a sequence of numbers (enter to exit): ')
return nums
The average
def average(numbers):
return sum(numbers) / len(numbers)
Standard deviation
def dev(numbers, average):
sdev = 0.0
for num in numbers:
sdev += (num - average) ** 2
return pow(sdev / len(numbers), 0.5)
Median
def median(numbers):
sorted(numbers)
size = len(numbers)
if size % 2 == 0:
return (numbers[size//2-1] + numbers[size//2]) / 2
else:
return numbers[size//2]
Absolute and relative errors
def rel_dev(numbers, average):
_max = max(abs(max(numbers) - average), abs(min(numbers) - average))
return _max, _max / average
def main():
nums = getNum()
if len(nums) == 0:
print(‘no data’)
else:
ave = average(nums)
devs = rel_dev(nums, ave)
print(‘ and :{:.4f}, The average :{:.4f}, Median :{:.4f}, variance :{:.4f}, Absolute error :{:4f}, Relative error :{:.4f}’
.format(sum(nums), ave, median(nums), dev(nums, ave), devs[0], devs[1]))
if name == ‘main’:
main()
边栏推荐
- Leetcode sum of two numbers
- Text editing VIM operation, file upload
- How to improve the level of pinduoduo store? Dianyingtong came to tell you
- TrueType字体文件提取关键信息
- Folio. Ink is a free, fast and easy-to-use image sharing tool
- 【Flask】获取请求信息、重定向、错误处理
- PHP campus movie website system for computer graduation design
- Open source | Ctrip ticket BDD UI testing framework flybirds
- 剑指 Offer 38. 字符串的排列
- Redis-字符串类型
猜你喜欢
Leetcode skimming questions_ Invert vowels in a string
[understanding of opportunity-39]: Guiguzi - Chapter 5 flying clamp - warning 2: there are six types of praise. Be careful to enjoy praise as fish enjoy bait.
Online reservation system of sports venues based on PHP
TrueType字体文件提取关键信息
UE4 unreal engine, editor basic application, usage skills (IV)
插卡4G工业路由器充电桩智能柜专网视频监控4G转以太网转WiFi有线网速测试 软硬件定制
Win10 add file extension
【clickhouse】ClickHouse Practice in EOI
Alibaba-Canal使用详解(排坑版)_MySQL与ES数据同步
Redis-字符串类型
随机推荐
Redis-Key的操作
Computer graduation design PHP enterprise staff training management system
Leetcode skimming questions_ Sum of squares
2022 PMP project management examination agile knowledge points (8)
阿里测开面试题
Using SA token to solve websocket handshake authentication
Folio.ink 免费、快速、易用的图片分享工具
Extracting key information from TrueType font files
Computer graduation design PHP part-time recruitment management system for College Students
Basic operations of databases and tables ----- primary key constraints
GBase 8c数据库升级报错
It's wrong to install PHP zbarcode extension. I don't know if any God can help me solve it. 7.3 for PHP environment
Computer graduation design PHP animation information website
A basic lintcode MySQL database problem
Campus second-hand transaction based on wechat applet
Tensorflow customize the whole training process
module ‘tensorflow. contrib. data‘ has no attribute ‘dataset
[the most complete in the whole network] |mysql explain full interpretation
Basic operations of database and table ----- delete data table
Grabbing and sorting out external articles -- status bar [4]