我试着编写一个代码,让你输入五个班级,其中有五个学生,然后输出结果会告诉你谁被重复,重复了多少次
前
输入:
约翰尼,莉莉,约翰尼,兰登,Miii
Wii,Random,Johnny,Lily,嗯
杰伊,约翰尼,兰登,Wii,呃
强尼,强尼,强尼,强尼,强尼
嗨,再见,例如,约翰尼
例如,例二,例三,例二,例三
输出:
约翰尼:10
莉莉:2
随机:3
Wii:2
谢谢:)
print('Each class has five students.')
a=input('Enter the first class students. ')
b=input('Enter the second class students. ')
c=input('Enter the third class students. ')
d=input('Enter the fourth class students. ')
e=input('Enter the fith class students. ')
我建议创建一个函数来处理这个问题
函数(它可以处理多个列表)
结果:
这里有一个不使用计数器的替代解决方案
下面是如何使用Counter():
注意:您必须首先将输入转换为列表。下面是如何做到这一点的(根据您的输入-您可以将
", "
更改为您想要的任何内容):相关问题 更多 >
编程相关推荐