2017-10-09 58 views
-1

這是我的第一篇文章在這裏計算器,這用Python做一個節目是我的第一次。我想打一個程序要求用戶學生輸入姓名,然後能夠更多信息添加到學生的程序繼續運行。理想我想用戶選擇多少學生有選擇多少個回合的玩法,給他們的名字,分配的分數,並在最後輸出的最終得分和每個學生的平均分。如何使用用戶輸入來確定程序的工作方式?

這是我目前:

name_students = list() 
num_students = input("How many students?: ") 
competitionRounds = input("How many rounds: ") 
score_students = list() 
myList = name_students 

for i in range(1, int(num_students) + 1): 
name_students.append(input("Student Name: ")) 
print(name_students) 


for i in range (1, int(competitionRounds)): 
print(input(name_students [0] + " Total Score for each round: ")) 

這是程序的運行方式:

How many student?: 3 #Have the user input answers to these questions 
How many rounds?: 2 
Student Name: Nick 
Student Name: Bob 
Student Name: Lisa 
Nick Total Score for each round: 

我一直想把它索要像

Nick Total Score for round 1: 
Bob Total score for round 1: 
Lisa Total score for round 1: 
Nick Total score for round 2: 
列出每一個名字

等等

我感謝任何回覆的人。

---編輯--- 所以,我現在有問題,取用戶輸入的數字,並將它們按用戶放置的名稱加在一起。

我的預期結果是: 尼克總得分的回合1:2 鮑勃總得分輪1:3 麗莎總得分輪1:1 尼克總成績爲第2輪:2 鮑勃總得分輪2:3 麗莎總成績爲第2輪:對於所有輪1個 尼克總比分:4 等

目前我的代碼如下所示:

name_students = list() 
num_students = input("How many students?: ") 
competitionRounds = input("How many rounds: ") 
score_students = [] 
myList = name_students 
total_scores = 0, [] 


for i in range(1, int(num_students) + 1): 
    name_students.append(input("Student Name: ")) 

for i in range (1, int(competitionRounds) +1): 
    for j in range(len(name_students)): 
    score_students.append(input(name_students [j] + " Total Score for round " + str(i) +": ")) 

for i in range (1,int(competitionRounds) +1): 
    for t in range(len(score_students)): 
     print(name_students + score_students + total_scores) 
+1

請妥善縮進代碼。 – Antimony

回答

1

您需要更改的最後一個循環

for i in range (1, int(competitionRounds)): 
    for j in range(len(name_students)): 
     score_students.append(input(name_students [j] + " Total Score for round " + str(i) + ": ")) 

這將要求用戶對每個學生的分數每一輪,並保留追加,爲score_students。然後你可以按照你想要的方式來操縱它。

How many students?: 2 
How many rounds: 3 
Student Name: A 
Student Name: B 
['A', 'B'] 
A Total Score for round 1: 2 
B Total Score for round 1: 1 
A Total Score for round 2: 2 
B Total Score for round 2: 1 
+0

嘿,謝謝你的回覆我真的很感激。我試過你的代碼,它工作。我遇到了將分數加在一起的問題,例如將第1輪和第2輪的分數加在一起。 – Infamous

+0

這是一個不同的問題。發佈你所嘗試過的細節以及你得到的錯誤。如果您當前的問題已得到解答,您應該接受答案。 – Antimony

相關問題