当前位置:网站首页>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 skimming questions_ Invert vowels in a string
- [flask] static file and template rendering
- Flowable source code comments (36) process instance migration status job processor, BPMN history cleanup job processor, external worker task completion job processor
- Redis list
- Redis如何实现多可用区?
- Thinking about the best practice of dynamics 365 development collaboration
- 【Flask】获取请求信息、重定向、错误处理
- GBase 8c数据库升级报错
- NumPy 数组索引 切片
- Kubernetes stateless application expansion and contraction capacity
猜你喜欢

Initialize MySQL database when docker container starts

插卡4G工业路由器充电桩智能柜专网视频监控4G转以太网转WiFi有线网速测试 软硬件定制

PHP campus financial management system for computer graduation design

Computer graduation design PHP part-time recruitment management system for College Students

2022 PMP project management examination agile knowledge points (8)

2022年PMP项目管理考试敏捷知识点(8)

Force buckle 1020 Number of enclaves

Derivation of Biot Savart law in College Physics

How does redis implement multiple zones?

Executing two identical SQL statements in the same sqlsession will result in different total numbers
随机推荐
Genius storage uses documents, a browser caching tool
Paddle框架:PaddleNLP概述【飛槳自然語言處理開發庫】
02.Go语言开发环境配置
Redis string type
Open source | Ctrip ticket BDD UI testing framework flybirds
2022年PMP项目管理考试敏捷知识点(8)
selenium 元素定位(2)
500 lines of code to understand the principle of mecached cache client driver
Online reservation system of sports venues based on PHP
[le plus complet du réseau] | interprétation complète de MySQL explicite
Basic operations of databases and tables ----- non empty constraints
Redis如何实现多可用区?
Basic operations of database and table ----- delete data table
[flask] obtain request information, redirect and error handling
GBase 8c数据库升级报错
2022 PMP project management examination agile knowledge points (8)
[flask] official tutorial -part3: blog blueprint, project installability
NLP第四范式:Prompt概述【Pre-train,Prompt(提示),Predict】【刘鹏飞】
[width first search] Ji Suan Ke: Suan tou Jun goes home (BFS with conditions)
NumPy 数组索引 切片