جواب «Step 3: Grade by Line» چالش 3 از جلسهی 16
سؤال
گزینهی 3 را اضافه کن: ساعت درس را بگیر و با مدل a=2.0, b=9 نمره را پیشبینی کن، بین 0 و 20 محدود کن و چاپ کن grade: 15. گزینههای 1 و 2 بمانند.
راهنما
elif choice == "3": hours = int(input()); grade = max(0, min(20, round(a * hours + b))); print("grade:", grade).
یک جواب درست
fruits = [(150, 9, "apple"), (160, 8, "apple"), (140, 10, "apple"), (60, 1, "lime"), (70, 2, "lime"), (55, 0, "lime")]
a, b = 2.0, 9
def knn(fruits, w, r, k):
scored = []
for fw, fr, name in fruits:
scored.append((((w - fw) ** 2 + (r - fr) ** 2) ** 0.5, name))
scored.sort()
votes = {}
for d, name in scored[:k]:
votes[name] = votes.get(name, 0) + 1
return max(votes, key=votes.get)
choice = input()
if choice == "1":
message = input().lower()
if "hello" in message:
print("Hi! I am your assistant.")
elif "help" in message:
print("Type 1 chat, 2 fruit, 3 grade, 4 report.")
else:
print("I do not understand.")
elif choice == "2":
w = int(input())
r = int(input())
print("fruit:", knn(fruits, w, r, 3))
elif choice == "3":
hours = int(input())
grade = max(0, min(20, round(a * hours + b)))
print("grade:", grade)
else:
print("coming soon")
اول خودت امتحان کن؛ جوابهای دیگر هم قبول است. برگرد و خودت حلش کن