Soy un novato y probé una calculadora de amor usando la lógica de mi cerebro y esto es lo que obtuve antes de algunos ajustes de aprendizaje del curso 100 Days of Code. No entiendo por qué obtengo '21' como mi respuesta si utilicé las respuestas instructivas proporcionadas por el maestro de 'Angela Yu' y 'Jack Bauer' como entrada, en lugar de 53, la respuesta correcta.
Me encantaría alguna orientación relacionada con la lógica. ¡Gracias!
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 <= 50:
print(f"Your score is {total_count}, you are alright together.")
else:
print(f"Your score is {total_count}.")
Solución del problema
En primer lugar, elimine la f en la declaración de impresión y se compilará. Hazlo así:
if total_count < 10 or total_count > 90:
print("Your score is {total_count}, you go together like coke and mentos.")
elif total_count >= 40 and total_count <= 50:
print("Your score is {total_count}, you are alright together.")
else:
print("Your score is {total_count}.")
.count("A") devuelve el número de ocurrencias del carácter "A" en una cadena. Por lo tanto, debe agregar estos recuentos sin convertirlos en cadenas. total_count =true_count + love_count
Además, creo que necesitas encontrar la verdad y el amor contar con cada nombre, lo cual no estás haciendo.
No hay comentarios:
Publicar un comentario