因此,我的 python 教授分配了一個練習,該練習是創建一個程式來接受用戶輸入或“分數”,并創建一個 if else 回圈,在第一個回圈中使用 if else 嵌套回圈來檢查分數是否大于或等于80. 如果滿意,列印一份宣告說“你通過了”。如果分數等于或大于 90,那么它應該說“你得了 A”。如果分數低于 80,它應該說“你失敗了”。
到目前為止,這是我能夠想出的代碼。它會一直運行,直到輸入的分數等于或大于 90。
userScore = int(input('enter score:\n'))
if userScore < 80:
userScore = int(input('you failed. Try again:\n'))
if userScore == 80 or userScore > 80:
print(f'good job, you got a B.')
elif userScore >= 90:
print('you got an A')
else:
print('enter a differnt score')
uj5u.com熱心網友回復:
根據您的問題,您的代碼應該是:
score = int(input("Please enter your score: "))
if score >= 80:
print("You passed.")
if score >= 90:
print("You got an A.")
else:
print("You failed.")
uj5u.com熱心網友回復:
while(1):
score = int(input("Please enter your score: "))
if score >= 80:
print("You passed.")
if score >= 90:
print("You got an A.")
break
else:
print("You failed.")
uj5u.com熱心網友回復:
while(1):
score = int(input("Please enter your score pal: "))
if score >= 80:
print("You passed the exam.")
if score >= 90:
print("You got an A in the exam.")
break
else:
print("You failed the exam.")
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/409583.html
標籤:
