分組串輸入我正在試圖做的一個問題了我的書,並問:通過計數
實現功能名稱,它沒有任何輸入,反覆詢問 用戶輸入一個學生的名字。當用戶輸入一個空白 字符串時,該功能應打印每個名稱,即具有該名稱的 學生的編號。
用法示例:
Usage:
names()
Enter next name: Valerie
Enter next name: Bob
Enter next name: Valerie
Enter next name: John
Enter next name: Amelia
Enter next name: Bob
Enter next name:
There is 1 student named Amelia
There are 2 students named Bob
There is 1 student named John
There are 2 students named Valerie
到目前爲止,我有這樣的代碼:
def names():
names = []
namecount = {a:name.count(a) for a in names}
while input != (''):
name = input('Enter next name: ')
names = name
if input == ('')
for x in names.split():
print ('There is', x ,'named', names[x])
我真的在這裏失去了任何的投入將助陣噸。另外,如果可能的話,請解釋如何修復我的代碼
@NPE我想他的意思來解釋我們的答案 – TerryA 2013-03-11 07:54:47
@Haidro是的,這就是我的意思,抱歉的混亂。我只是真的迷失在這裏,而我一直在這個問題上掙扎了一段時間。 – JGrazza 2013-03-11 07:56:08