Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

day07 scoretable #81

Open
muir-yh opened this issue May 10, 2019 · 1 comment
Open

day07 scoretable #81

muir-yh opened this issue May 10, 2019 · 1 comment

Comments

@muir-yh
Copy link

muir-yh commented May 10, 2019

hello,day07,scoretable.py,运行后5人成绩均为最后一人,或许5人的成绩list都为同一个引用。
将main()改为如下即可,如有更好办法请更新,我会继续学习,谢谢!

def main():
       names = ['关羽', '张飞', '赵云', '马超', '黄忠']
       subjs = ['语文', '数学', '英语']`
       scores = list()
       t_scores = [None]*3
       for row, name in enumerate(names):
           print('请输入%s的成绩' % name)
           for col, subj in enumerate(subjs):
               t_scores[col] = float(input(subj + ': '))
           scores.append(t_scores)
       print(scores)
`
@clunyes
Copy link

clunyes commented Dec 25, 2019

def main():
    names = ['关羽', '张飞', '赵云', '马超', '黄忠']
    subjs = ['语文', '数学', '英语']
    scores = [[0] * 3 for i in range(5)]
    for row, name in enumerate(names):
        print('请输入%s的成绩' % name)
        for col, subj in enumerate(subjs):
            scores[row][col] = float(input(subj + ': '))
    print(scores)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants