導航:首頁 > 編程語言 > 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輸出的數不相同的數字相關的資料

熱點內容
dns使用加密措施嗎 瀏覽:172
php獨立運行 瀏覽:530
手機sh執行命令 瀏覽:727
雲伺服器的角色 瀏覽:733
單片機頻率比例 瀏覽:840
我的世界伺服器如何關閉正版驗證 瀏覽:504
如何查roid伺服器上的 瀏覽:130
安卓手機主板如何撬晶元不掉電 瀏覽:249
php各個框架的優缺點 瀏覽:101
php1100生成數組 瀏覽:359
以後做平面設計好還是程序員好 瀏覽:552
雲伺服器應用管理 瀏覽:438
飢荒雲伺服器搭建過程 瀏覽:186
可編程式控制制器優點 瀏覽:99
壓縮垃圾車說明書 瀏覽:28
五輪書pdf 瀏覽:802
單片機定時流水中斷系統流水燈 瀏覽:701
u8如何連接伺服器配置 瀏覽:68
動力在於緩解壓力 瀏覽:867
報考科一用什麼app 瀏覽:346