久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 Python 中,如何在循環(huán)中獲取總和和平均值

In Python, how to get the sum and average while in a loop(在 Python 中,如何在循環(huán)中獲取總和和平均值)
本文介紹了在 Python 中,如何在循環(huán)中獲取總和和平均值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我已經(jīng)設(shè)法實現(xiàn)了一個循環(huán),但是當(dāng)我嘗試 sum 函數(shù)時不斷收到語法錯誤.我需要匯總用戶輸入的數(shù)字并給出平均值.這必須輸出給用戶.您能否指導(dǎo)我從這里去哪里,謝謝.

這是我到目前為止所做的:

I've managed to implement a loop but keep getting a syntax error when I try the sum function. I need the numbers input by the user to be totalled and the average given as well. This has to be outputted to the user. Could you please guide me on where to go from here, thank you.

This is what I've done so far:

while 1:
    NumCalc = input ("Enter Number :")
    if NumCalc == "done": break

推薦答案

如果您想在循環(huán)結(jié)束后計算總和和平均值,您可以這樣做:

This is what you can do if you want to compute the sum and the mean after the loop ends:

nums = []
while 1:
    NumCalc = input ("Enter Number:")
    if NumCalc == "done": break
    nums.append(float(NumCalc))

print('Sum:', sum(nums), 'and average:', sum(nums)/len(nums))

<小時>循環(huán)中:

s = 0.0
counter = 0

while 1:
    NumCalc = input("Enter Number: ")
    if NumCalc == "done":
        break

    NumCalc = float(NumCalc)
    s += NumCalc
    counter += 1


    print('Sum is', s, 'and the mean is', s/counter)

輸出:

Enter Number: 5
Sum is 5.0 and the mean is 5.0
Enter Number: 2
Sum is 7.0 and the mean is 3.5
Enter Number: 4
Sum is 11.0 and the mean is 3.66666666667
Enter Number: 6
Sum is 17.0 and the mean is 4.25
Enter Number: 2
Sum is 19.0 and the mean is 3.8

這篇關(guān)于在 Python 中,如何在循環(huán)中獲取總和和平均值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區(qū)域周圍繪制一個矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個矩形邊界框中應(yīng)用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據(jù)文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 中文字幕亚洲一区 | 国产高清亚洲 | 成人网在线观看 | 蜜臀网 | av一级在线观看 | 羞羞的视频免费在线观看 | 国产精品揄拍一区二区 | 伊人热久久 | 久久亚洲国产精品日日av夜夜 | 国产精品一区二区av | 久久精品国产一区二区电影 | 2018天天干天天操 | 成人免费在线观看 | 美女拍拍拍网站 | 欧美日韩高清 | 在线三级电影 | 一区二区三区精品视频 | 国产探花在线精品一区二区 | 自拍偷拍精品 | 人妖无码 | 草逼网站 | 中文字幕一区二区三区四区 | 欧美日韩国产一区二区三区 | 成人在线一区二区三区 | 国产情侣久久 | 亚洲国产精品久久久久秋霞不卡 | 人妖av| 亚洲一区中文字幕在线观看 | 中国黄色毛片视频 | jdav视频在线观看免费 | 国产99久久精品一区二区300 | 91麻豆精品一区二区三区 | 午夜男人免费视频 | 国产精品久久 | 亚洲欧美一区二区三区在线 | 中文亚洲视频 | 亚洲成av | 日本一区二区三区视频在线 | 色婷婷综合久久久中字幕精品久久 | 影音先锋成人资源 | 精品国产视频 |