iT邦幫忙

0

簡單的python問題

要怎麼讓我的輸出
「A,B,C,D,F」在同一行
這是我的程式
def calc_average(n):
average = (a+b+c+d+e)/5
print(average)
return average

def determine_grade(n):
if n >= 90:
print("A")
elif n >= 80 and n < 90:
print("B")
elif n >= 70 and n < 80:
print("C")
elif n >= 60 and n < 70:
print("D")
else:
print("F")

def grade(n):
n = int(input())
determine_grade(n)
return n

a=grade(1)
b=grade(2)
c=grade(3)
d=grade(4)
e=grade(5)

calc_average(a+b+c+d+e)

Lin2602 iT邦新手 5 級 ‧ 2021-07-31 05:56:14 檢舉
用 ``` 包住程式碼,可以避免跑版。
gjlmotea iT邦新手 5 級 ‧ 2021-08-05 01:05:52 檢舉
print的時候帶入end參數取代預設的換行 print("A", end = " ")

2 個回答

1
Vmtayvj
iT邦新手 5 級 ‧ 2021-07-30 04:39:04
最佳解答

你到底在寫什麼...

def getAverage(n, nCount):
    return n / nCount

def printGrade(n):
    if 90 <= n < 100:
        print("A")
    elif 80 <= n < 90:
        print("B")
    elif 70 <= n < 80:
        print("C")
    elif 60 <= n < 70:
        print("D")
    else:
        print("F")

def getScoreFromInputThenPrintGrade():
    n = int(input())
    printGrade(n)
    return n

a = getScoreFromInputThenPrintGrade()
b = getScoreFromInputThenPrintGrade()
c = getScoreFromInputThenPrintGrade()
d = getScoreFromInputThenPrintGrade()
e = getScoreFromInputThenPrintGrade()

print(getAverage(a+b+c+d+e, 5))
0
cloudyang
iT邦新手 5 級 ‧ 2021-07-31 12:52:40

print("A",end='') ?

我要發表回答

立即登入回答