第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

你如何在 Python 中使用數組輸入用戶的字符列表

你如何在 Python 中使用數組輸入用戶的字符列表

喵喵時光機 2021-12-21 16:15:21
我正在嘗試構建一個基本程序,該程序將從用戶那里獲取名稱,并將顯示包含 5 個以上字母的名稱數量。from array import*list=array('u',[])n=int(input("Enter the number of names first"))for i in range(0,n):    y=input("Enter the names one by one")    list.append(y)但是當運行此代碼時,我收到一個錯誤“類型錯誤:數組項必須是 unicode 字符”
查看完整描述

2 回答

?
不負相思意

TA貢獻1777條經驗 獲得超10個贊

繼續(xù)評論,保持簡單以便您理解:


n = int(input("Enter the number of names first"))


nameLst = []           # an empty list to store the desired names

for i in range(0,n):

    y = input("Enter the names one by one")     

    if len(y) > 5:               # if the len of name is > 5

        nameLst.append(y)        # append it to the list


for i in range(len(nameLst)):    # iterate over the len of the list

    print(nameLst[i])            # print all the names in the list


查看完整回答
反對 回復 2021-12-21
?
三國紛爭

TA貢獻1804條經驗 獲得超7個贊

n=int(input('enter times : '))

name =list(map(str, input("enter name spe by space : ").strip().split()))

if len(name)==n:

    name2 =[i for i in name if len(i)>=5]

    print("name are ->", *name2)


"""

output 


enter times : 3


enter name spe by space : john edward philips

name are -> edward philips


"""


查看完整回答
反對 回復 2021-12-21
  • 2 回答
  • 0 關注
  • 217 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號