题解 | #姓名与学号#
姓名与学号
https://www.nowcoder.com/practice/ab68195587de46c59e2d327a4942d345
my_dict_1 = {"name": "Niuniu", "Student ID": 1} my_dict_2 = {"name": "Niumei", "Student ID": 2} my_dict_3 = {"name": "Niu Ke Le", "Student ID": 3} dict_list = [] dict_list.append(my_dict_1) dict_list.append(my_dict_2) dict_list.append(my_dict_3) for info in dict_list: print(f"{info['name']}'s student id is {info['Student ID']}.")
哇!!!使用字符串时一定要避免语法错误!!!在字符串中要正确使用单引号和双引号!!!
语法错误是最不具体的错误类型!因此很可能难以找出并修复!!!最起码这次对我来说是这样的!!!
刚开始调试代码的时候一直出错,一度怀疑是软件判题出了问题;清空代码之后重写,调试还是不行,看看大家提交的代码,看着也是一样的,也看不出有什么区别,干脆就直接不调试直接提交了,提交直接报错。后来不知道怎么阴差阳错地就想起了单引号和双引号的搭配使用,啊,这次竟然成功了!
my_dict_1 = {"name": "Niuniu", "Student ID": 1}
my_dict_2 = {"name": "Niumei", "Student ID": 2}
my_dict_3 = {"name": "Niu Ke Le", "Student ID": 3}
dict_list = []
dict_list.append(my_dict_1)
dict_list.append(my_dict_2)
dict_list.append(my_dict_3)
for info in dict_list:
print(f"{info["name"]}'s student id is {info["Student ID"]}.") # 就是他就是他,罪魁祸首就是他!
#Python学旅#