100 Tage Code – 37 – Liebesrechner – Was stimmt mit meinem Code nicht?Python

Python-Programme
Anonymous
 100 Tage Code – 37 – Liebesrechner – Was stimmt mit meinem Code nicht?

Post by Anonymous »

Neuling hier und ich habe versucht, mithilfe der Logik in meinem Gehirn einen Liebesrechner zu verwenden, und hier ist, was ich vor einigen Lernoptimierungen aus dem 100-Tage-Code-Kurs erhalten habe. Ich bin ratlos, warum ich „21“ als Antwort bekomme, wenn ich die vom Lehrer bereitgestellten Lehrantworten „Angela Yu“ und „Jack Bauer“ als Eingabe verwendet habe, im Gegensatz zu 53, der richtigen Antwort.
Ich würde mich über eine Anleitung zur Logik freuen. Danke!

Code: Select all

name1_lower = name1.lower()
name2_lower = name2.lower()

t_count = name1_lower.count("t")
r_count = name1_lower.count("r")
u_count = name1_lower.count("u")
e_count = name1_lower.count("e")
true_count = t_count + r_count + u_count + e_count

l_count = name2_lower.count("l")
o_count = name2_lower.count("o")
v_count = name2_lower.count("v")
e2_count = name2_lower.count("e")
love_count = l_count + o_count + v_count + e2_count

total_count = int(str(true_count) + str(love_count))

#I learned to convert the above to string, and then back to integer
# from Dr. Yu, didn't have this initially
# perhaps I need to do the same above to true_count and love_count?

if total_count < 10 or total_count > 90:
print(f"Your score is {total_count}, you go together like coke and mentos.")
elif total_count >= 40 and total_count

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post