python用户重复输入_在Python中从用户输入中查找重复值

我最初的代码是Python2.7.8中的一个基本计算器,但现在我决定加入一个用户可以输入多个值的函数。在

一旦输入了这些值,函数就可以运行,用户刚刚输入的值存储在一个变量中(函数参数),然后被告知他们是否输入了重复的值,这些值在逗号处被拆分,并被插入到一个列表中,然后函数运行。在

我已经创建了一个函数,它已经接受了与用户输入的AlgorithmListEntry相等的变量,当用户键入算法时会发生这种情况。在def findDuplicates(AlgorithmListEntry):

for i in len(range(AlgorithmListEntry)):

for j in len(1,range(AlgorithmListEntry)):

if AlgorithmListEntry[i]==AlgorithmListEntry[j]:

return True

return False

其中,函数也会查找参数的范围,但由于另一个错误,此操作不起作用

^{pr2}$

我现在收到一个错误for i in len(AlgorithmListEntry):TypeError: 'int' object is not iterable

为了便于查看,我只插入了与我的问题相关的代码部分i = True #starts outer while loop

j = True #inner scientific calculations loop

def findDuplicates(AlgorithmListEntry):

for i in len(AlgorithmListEntry):

for j in len(1(AlgorithmListEntry)):

if AlgorithmListEntry[i]==AlgorithmListEntry[j]:

return True

return False

while i==True:

UserInput=raw_input('Please enter the action you want to do: add/sub or Type algorithm for something special: ')

scienceCalc=('Or type other to see scientific calculations')

if UserInput=='algorithm':

listEntry=raw_input('Please enter numbers to go in a list:').split(",")

AlgorithmListEntry = list(listEntry)

print AlgorithmListEntry

print "The program will now try to find duplicate values within the values given"

findDuplicates(AlgorithmListEntry)

#i = False

问题为什么我会收到这两个错误?

如何在程序中成功实现此功能?这样用户就可以收到关于他们输入的值是否包含重复值的反馈?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值