该程序应该采用两个名称,如果它们的长度相同,则应检查它们是否是同一个单词。如果它是相同的单词,它将打印“名称相同”。如果它们长度相同但字母不同,则会打印“名称不同但长度相同”。我遇到问题的部分是在底部4行。
#!/usr/bin/env python
# Enter your code for "What's In (The Length Of) A Name?" here.
name1 = input("Enter name 1: ")
name2 = input("Enter name 2: ")
len(name1)
len(name2)
if len(name1) == len(name2):
if name1 == name2:
print ("The names are the same")
else:
print ("The names are different, but are the same length")
if len(name1) > len(name2):
print ("'{0}' is longer than '{1}'"% name1, name2)
elif len(name1) < len(name2):
print ("'{0}'is longer than '{1}'"% name2, name1)
当我运行此代码时,它显示:
Traceback (most recent call last):
File "program.py", line 13, in <module>
print ("'{0}' is longer than '{1}'"% name1, name2)
TypeError: not all arguments converted during string formatting
任何建议都非常感谢。
慕桂英546537
倚天杖
相关分类