python
1 2cnt = 0 3g = 0 4grade = [] 5while(1): 6 cnt += 1 7 g = int(input('Enter grade '+str(cnt) + ': ')) 8 if g==-1: 9 break 10 else: 11 grade.append 12 13 14 15 16avg = sum(grade)/len(grade) 17print('Average :' + str(avg)) 18 19 20if 90 <= avg: 21 grade = 'A++' 22elif 80 <= avg: 23 grade = 'A+' 24elif 70 <= avg: 25 grade = 'A' 26elif 60 <= avg: 27 grade = 'B' 28elif 50 <= avg: 29 grade = 'C' 30elif 40 <= avg: 31 grade = 'D' 32elif 33 <= avg: 33 grade = 'F+' 34elif 20 <= avg: 35 grade = 'F' 36else: 37 grade = 'FF' 38print ('Your grade is:{} '.format(avg)) 39
とこのようにつくってみたのですが、動作しません。
ほかにもいろいろ考えて
gradeの部分は
前に考えたことがあったのですが。
どうしたら問題のようにくっつけられるのかわかりません。
a = int(input("ENTER YOUR 1ST GRADE"))
b = int(input("ENTER YOUR 2ST GRADE"))
c = int(input("ENTER YOUR 3ST GRADE"))
ave = (a+b+c)/3
if 90 <= ave <=100:
g = "A++"
elif 80 <= ave <= 89:
g = "A+"
elif 70 <= ave <= 79:
g = "A"
elif 60 <= ave <= 69:
g = "B"
elif 50 <= ave <= 59:
g = "C"
elif 40 <= ave <= 49:
g = "D"
elif g <= 39:
g = "F"
print("Average is {}".format(ave))
print("Your grade is {}".format(g))```Python
回答1件
あなたの回答
tips
プレビュー