日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python如何计算个人gpa_使用While循环(Python)计算GPA

發布時間:2023/12/18 python 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python如何计算个人gpa_使用While循环(Python)计算GPA 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

GPA或平均分數是通過將學生課程中獲得的分數相加,然后除以總單位計算出來的。對于個別課程的等級分是由根據等級的相應系數為課程單位乘以收到:使用While循環(Python)計算GPA

A receives 4 grade points

B receives 3 grade points

C receives 2 grade points

D receives 1 grade point

F receives 0 grade point

你的程序有一個while循環來計算多的GPA和while循環收集個人成績(即一個嵌套的while循環)。

對于您的演示,計算GPA到小數點后2位,這兩個組合的過程:

First Case: 5 units of A 4 units of B 3 units of C

Second Case: 6 units of A 6 units of B 4 units of C

這是我到目前為止....

todo = int(input("How many GPA's would you like to calculate? "))

while True: x in range (1, todo+1)

n = int(input("How many courses will you input? "))

totpoints = 0

totunits = 0

while True: range(1, n+1)

grade = input("Enter grade for course: ")

if grade == 'A':

grade = int(4)

if grade == 'B':

grade = int(3)

if grade == 'C':

grade = int(2)

if grade == 'D':

grade = int(1)

if grade == 'F':

grade = int(0)

units = int(input("How many units was the course? "))

totunits += units

points = grade*units

totpoints += points

GPA = totpoints/totunits

print("GPA is ", ("%.2f" % GPA))

print("total points = ", totpoints)

print("total units = ", totunits)

我的問題是如何我是否正確地加入了while函數?我的代碼運行不正常。

在此先感謝。

+1

您不需要'while'循環,因為您'重新使用'for'循環代替。這通常更具慣用性和可讀性,但如果你的任務需要一個'while'循環,你將不得不重寫它以使用它。 –

2014-09-30 19:40:22

+0

換句話說:您需要為'x'設置一個起始值,然后使用'while(某些條件在x上):',然后在循環內部以某種方式更新'x'。 –

2014-09-30 19:41:01

+0

所以我只是用它來替換它?如果其他的elif函數不需要嗎? –

2014-09-30 19:41:37

總結

以上是生活随笔為你收集整理的python如何计算个人gpa_使用While循环(Python)计算GPA的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。