导航:首页 > 编程语言 > python输出的数不相同的数字

python输出的数不相同的数字

发布时间:2022-04-17 09:15:43

❶ 用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)

阅读全文

与python输出的数不相同的数字相关的资料

热点内容
华为媒体算法工程师 浏览:650
pdf怎么转txt 浏览:689
售乐实物商城源码 浏览:674
php的资源标识符 浏览:623
联通app怎么交电视费 浏览:729
怎么从服务器切回自己的电脑 浏览:105
用生硬的命令成语 浏览:992
数据结构与算法大作业 浏览:149
英特尔支持加密货币购买吗 浏览:407
苹果如何玩安卓号的部落冲突 浏览:863
还原魔方算法c 浏览:849
树莓派如何变成服务器 浏览:251
google浏览器app怎么用 浏览:458
安卓充游戏怎么退款网易游戏 浏览:266
gre词汇精选pdf 浏览:666
荣耀20i照片加密 浏览:633
phpshtml 浏览:207
高中生玩乐队能解压吗 浏览:882
物理服务器如何租用 浏览:100
战地1是什么服务器 浏览:957