我最近试着用这段代码做一个爱情计算器。然而,当一个名字有超过11个共同的“爱”或“真”字符时,它不会返回正确的语句。例如,如果因为'love'语句超过9而返回711,它只会给我'else'选项,而不是=>;90声明。我不确定我做错了什么。提前感谢您的帮助
print("Welcome to the Love Calculator!")
name1 = input("What is your name? \n")
name2 = input("What is their name? \n")
combined_names = str(name1.lower()) + str(name2.lower())
t = combined_names.count('t')
r = combined_names.count('r')
u = combined_names.count('u')
e = combined_names.count('e')
l = combined_names.count('l')
o = combined_names.count('o')
v = combined_names.count('v')
e = combined_names.count('e')
Love = l + o + v + e
true = t + r + u + e
truelove = int(str(true) + str(Love))
if truelove <= 10 and truelove >= 90:
print(f"Your score is {truelove}, you go together like coke and mentos")
elif truelove >= 40 and truelove <= 50:
print(f"Your score is {truelove}, you are alright together")
else:
print(f"Your score is {truelove}")
将始终给出
false
而不传递此if语句要运行它,您可以尝试
编辑:我看到您的
elif
语句永远不会工作,因为第一个if
语句的范围更广。因此,翻转if语句将修复它相关问题 更多 >
编程相关推荐