我正在尝试比较用户列表中2个元素的相似性以及它们作为整数的给定答案,以百分比与用户给定的输入限制进行比较,如何根据用户输入进行识别,仅在其中分离和比较整数值一会儿循环吗?
这是示例输出
You can check up to 3 pairs
Please provide the first name in the pair (or END to finish) ==> A
Please provide the second name in the pair ==> B
** Sorry! at least one name is not in the data
Another pair? provide the first name (or END to finish) ==> AAAAA
Please provide the second name in the pair ==> AAAAA
TRACE similars 21
** A and B really have a lot in common (>90%)!
Another pair? provide the first name (or END to finish) ==> AAAAA
Please provide the second name in the pair ==> K
TRACE similars 5
** A and K have just few opinions in common (<50%)!
***** Sorry you cannot check more pairs.. you reached the maximum: 5
我的尝试
maxPairs = int(input("What is the maximum number of pairs you want to try? ==> "))
list=[A 1 2, B 4 5,C 6 7]
listofLists=[[A 1 2],[B 4 5],[C 6 7]
firstname=int(input("Please provide the first name in the pair (or END to finish) ==>"))
if firstname!='END':
secname=int(input("Please provide the first name in the pair (or END to finish) ==>"))
else:
sys.exit
numP=0
while numP<maxPairs:
for lst in range (listofLists):
if firstname=listofLists[lst]:
pear=item[0]=listofLists[lst]
itemlist[0]==listofLists
listst==listoflists[lst[1]]
if secname=listofLists[lst]:
pear=item[0]=listofLists[lst]
itemlist[0]==listofLists
seclistst==listoflists[lst[1]]
if lstst=seclistst:
print(firstname ,"and", secname, "really have a lot in common (>90%)!")
else:
print("** Sorry! at least one name is not in the data")
??????
nump+=1
对于可能因为不清楚或令人困惑而拒绝这篇文章的人,我也不明白,我正在尽力而为。请至少给出您遇到的问题的原因,建议或解决方案。