当前位置:网站首页>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()
边栏推荐
- SQL statement
- Flutter Doctor:Xcode 安装不完整
- Xshell 7 Student Edition
- Redis list
- Cookie concept, basic use, principle, details and Chinese transmission
- leetcode-2.回文判断
- Jisuanke - t2063_ Missile interception
- 01. Go language introduction
- Apicloud openframe realizes the transfer and return of parameters to the previous page - basic improvement
- Leetcode3. Implement strstr()
猜你喜欢
安装php-zbarcode扩展时报错,不知道有没有哪位大神帮我解决一下呀 php 环境用的7.3
使用npm发布自己开发的工具包笔记
Alibaba canal usage details (pit draining version)_ MySQL and ES data synchronization
Redis-字符串类型
[depth first search] Ji Suan Ke: Betsy's trip
Initialize MySQL database when docker container starts
A Cooperative Approach to Particle Swarm Optimization
[detailed] several ways to quickly realize object mapping
How to improve the level of pinduoduo store? Dianyingtong came to tell you
干货!通过软硬件协同设计加速稀疏神经网络
随机推荐
MySQL index
Cadre du Paddle: aperçu du paddlelnp [bibliothèque de développement pour le traitement du langage naturel des rames volantes]
Blue Bridge Cup embedded_ STM32_ New project file_ Explain in detail
Apicloud openframe realizes the transfer and return of parameters to the previous page - basic improvement
This time, thoroughly understand the deep copy
Computer graduation design PHP college student human resources job recruitment network
How to use C to copy files on UNIX- How can I copy a file on Unix using C?
【Flask】官方教程(Tutorial)-part1:项目布局、应用程序设置、定义和访问数据库
抓包整理外篇——————状态栏[ 四]
阿裏測開面試題
[flask] official tutorial -part3: blog blueprint, project installability
Redis key operation
【Flask】官方教程(Tutorial)-part2:蓝图-视图、模板、静态文件
Shutter doctor: Xcode installation is incomplete
How to upgrade kubernetes in place
dried food! Accelerating sparse neural network through hardware and software co design
MCU lightweight system core
Unity learning notes -- 2D one-way platform production method
Computer graduation design PHP college classroom application management system
[solved] how to generate a beautiful static document description page