Hier gleich meine Aufgabe ist:Need a, b, c zusammenzufassen, es sei denn, sie 13,14,17,18,19
Gegeben 3 int Werte, a b c, deren Summe zurück. Wenn jedoch einer der Werte ein Teenager ist - im Bereich von 13.19 inklusive - dann zählt dieser Wert als 0, außer 15 und 16 zählen nicht als Teenager. Schreibe einen separaten Helfer "def fix_teen (n):", der einen int-Wert annimmt und den für die Teen-Regel festgelegten Wert zurückgibt. Auf diese Weise vermeiden Sie, den Teen-Code dreimal zu wiederholen (d. H. "Zerlegung"). Definieren Sie das Hilfeprogramm unterhalb und auf derselben Ebene wie das Hauptelement no_teen_sum().
Hier ist die einzige Lösung, die ich tun konnte:
excep = [13,14,17,18,19]
def no_teen_sum(a, b, c):
if a in excep and b in excep and c in excep:
return 0
elif a in excep and b in excep and c not in excep:
return c
elif b in excep and c in excep and a not in excep:
return a
elif a in excep and c in excep and b not in excep:
return b
elif a in excep and b not in excep and c not in excep:
return b+c
elif b in excep and a not in excep and c not in excep:
return a+c
elif c in excep and a not in excep and b not in excep:
return a+b
else:
return a+b+c
Ist dieser Code Python? –
Ja ist in Python –
Nun Tag die Frage als Python –