【发布时间】:2014-07-20 20:35:25
【问题描述】:
编写一个python程序。所有相邻的重复项。例如,如果输入是 1 3 3 4 5 5 6 6 6 2, 程序应该打印 3 5 6。
这是我目前所拥有的:
print("Take out repeating numbers")
def main():
a = int(input("Enter a number: "))
b = int(input("Enter a number: "))
c = int(input("Enter a number: "))
d = int(input("Enter a number: "))
e = int(input("Enter a number: "))
f = int(input("Enter a number: "))
g = int(input("Enter a number: "))
if a == a:
print(a)
elif a == b:
print(a)
elif a == c:
print(a)
elif a == d:
print(a)
elif a == e:
print(a)
elif a == f:
print(a)
else:
print(a)
if b == a:
print(b)
elif b == b:
print(b)
elif b == c:
print(b)
elif b == d:
print(b)
elif b == e:
print(b)
elif b == f:
print(b)
else:
print(b)
if c == a:
print(c)
elif c == b:
print(c)
elif c == c:
print(c)
elif c == d:
print(c)
elif c == e:
print(c)
elif c == f:
print(c)
else:
print(c)
'''
if d == a or d == b or d == c or d == d or d == e or d == f or d == g:
print(d)
if e == a or e == b or e == c or e == d or e == e or e == f or e == g:
print(e)
if f == a or f == b or f == f or f == d or f == e or f == f or f == g:
print(f)
if g == a or g == b or g == c or g == d or g == e or g == f or g == g:
print(g)
'''
print("The repeating numbers are: " , a, b, c, d, e, f, g,)
main()
它只是打印出所有输入
【问题讨论】:
-
你可能想看看循环..
-
列表切片也会对你有所帮助(假设你重组了你持有价值观的方式)。
nums[0:2]-> 列表前面的两个元素。 -
因为
a == a和b == b总是True,所以会打印整个列表。
标签: python python-3.2