جواب «Best and Lowest» چالش 4 از جلسهی 10
سؤال
اپ نمره: کادر Score و دکمهی Add. تابع add را کامل کن: نمره را به شکل عدد در scores بگذار، کادر را خالی کن، و دو متن را بنویس: Best: 12 (بیشترین) و Lowest: 7 (کمترین). مثلاً ۹، ۱۲ و ۷ ← Best: 12 و Lowest: 7. (حرف و کادر خالی را در این تمرین نمیزنیم.)
راهنما
scores.append(int(score.value))، بعد score.value = ""، بعد best.value = f"Best: {max(scores)}" و همین با min برای low. بدون int نمرهی ۹ از ۱۲ «بزرگتر» میشود!
یک جواب درست
import app
scores = []
def add():
scores.append(int(score.value))
score.value = ""
best.value = f"Best: {max(scores)}"
low.value = f"Lowest: {min(scores)}"
app.title("My Scores")
score = app.number("Score")
app.button("Add", add)
best = app.text("Best: -")
low = app.text("Lowest: -")
app.run()
اول خودت امتحان کن؛ جوابهای دیگر هم قبول است. برگرد و خودت حلش کن