语法错误:真爱练习中的语法无效,我找不到问题



我正在学习Python,下面的代码有问题。对我来说似乎一切都很好,但我总是犯错误。怎么了?

# 🚨 Don't change the code below 👇
print("Welcome to the Love Calculator!")
name1 = input("What is your name? n")
name2 = input("What is their name? n")
# 🚨 Don't change the code above 👆
#Write your code below this line 👇
combined_name=name1+name2
combined_name_lower = combined_name.lower()
t = combined_name_lower.count("t")
r = combined_name_lower.count("r")
u = combined_name_lower.count("u")
e = combined_name_lower.count("e")
true = t + r + u + e
l = combined_name_lower.count("l")
o = combined_name_lower.count("o")
v = combined_name_lower.count("v")
e = combined_name_lower.count("e")
love = l + o + v + e
love_score = int(str(true) + str(love))
if love_score < 10 or > 90:
print(f"Your score is {love_score}, you go together like coke and mentos.")
elif love_score >= 40 and <= 50:
print(f"Your score is {love_score}, you are alright together.")
else:
print(f"Your score is {love_score}.")

您应该在帖子中包含错误消息:

File "main.py", line 29
if love_score < 10 or > 90:
^
SyntaxError: invalid syntax

问题在于您尝试使用的比较语法。应该是

if not 10 <= love_score <= 90:

if love_score < 10 or love_score > 90:

只是一个拼写错误,用更正

if love_score < 10 or love_score > 90:
elif love_score >= 40 and love_score <= 50:

相关内容

最新更新