❶ 用python编写程序,输入16个整数,输出其中出现了多少个相同的数字要求输入:一
代码:
from collections import Counter
a = []
for i in range(16):
a.append(int(input("input score:"))) #注意缩进,网络太对代码太不友好了
b = dict(Counter(a))
print ("repeated nums:(value:count)")
print ({key:value for key,value in b.items()if value > 1})
输出:
input score:1
input score:2
input score:3
input score:4
input score:5
input score:6
input score:7
input score:8
input score:9
input score:10
input score:10
input score:9
input score:9
input score:8
input score:7
input score:7
repeated nums:(value:count)
{8: 2, 9: 3, 10: 2, 7: 3}
❷ Python中怎么输出由英文大小写字母或者数字组成的长度为10的且不重复的字符串
# encoding: utf-8
# Python 3.6.0
import random
s=''
print(''.join(random.sample(list(s),10)))
❸ 怎么用python编程 输入十个不同的数字,输出其中最大的数和第二大的数
#终端运行python3test.py1.12345678910.5
#输出
#max:10.5
#second:9.0
#将以下写入文本test.py
importsys
input=[float(i)foriinsys.argv[1:]]#可以在这直接写多个数
input.sort(reverse=True)
print("max:",input[0])
print("second:",input[1])
❹ python接收从键盘输入的一串字符串,输出其中不同的字符以及它们各自的字数
试试这个代码python3.x
s=input('请输入字符串:')
ms=set(s)
foriteminms:
print('字符:',item,'数量:',s.count(item))
❺ 用python把A,B两文本里相同行找出不同数字
python
a_str=''
b_str=''
withopen('A.txt',"r")asf:
a_str=f.read()
withopen('B.txt',"r")asf:
b_str=f.read()
al=a_str.split(',')
bl=b_str.split(',')
result=set(al)^set(bl)
print(','.join(sorted(result)))
结果

❻ 2.输入一个整数,输出它由多少个不同的数组成。用python
print(len(set(input())))
❼ python 随机抽取不重复的数字
def ra(ktop=1,kend=2000,kbu=2,fansize=500):
"""ktop开始,kend结束,kbu步长,fansize返回个数"""
import random
a=[]
while len(a)<fansize:
b=random.randrange(ktop,kend,kbu)
if b not in a:
a.append(b)
return a
print ra()
#输出类似[1,31,3,81,5……]等。
❽ python编程 输入十个不同的数字,输出其中最大的数和次大的数。
#python2下的代码:
test=input('请输入一个数组:')
temp=sorted(test)
print '从小到大排序得:',temp
print '您输入的数组中,最大的数为:%g'%temp[-1]
print '您输入的数组中,第二大大的数为:%g'%temp[-2]
'------------------------------------'
#python3下的代码:
test=input('请输入一个数组:')
temp=[]
for i in test.split(','):
temp.append(int(i))
temp=sorted(temp)
print('从小到大排序得:',temp)
print('您输入的数组中,最大的数为:%g'%temp[-1])
print('您输入的数组中,第二大大的数为:%g'%temp[-2])
❾ 编写Python程序,打印出由6,7,8,9共四个数字组成的互不相同且无重复数字的三位
#-*-coding:utf-8-*-
if__name__=="__main__":
wordList=[6,7,8,9]
forperWordinwordList:
forperWord2inwordList:
ifperWord==perWord2:
continue
forperWord3inwordList:
ifperWord2==perWord3orperWord==perWord3:
continue
print(perWord*100+perWord2*10+perWord3)
