用pytho写1. 从键盘上输入,添加4个学生的信息(姓名、学号,性别、分数),并打印 2. 在每个学生的信息里添加身高信息(’height’:185) 3. 将第二个同学的分数修改为90分 4. 删除第三个同学的信息
时间: 2024-02-23 07:58:08 浏览: 22
可以使用Python的字典(Dictionary)来存储每个学生的信息,代码如下:
```python
# 输入4个学生的信息
students = []
for i in range(4):
student = {}
student['name'] = input('请输入第{}个学生的姓名:'.format(i+1))
student['id'] = input('请输入第{}个学生的学号:'.format(i+1))
student['gender'] = input('请输入第{}个学生的性别:'.format(i+1))
student['score'] = int(input('请输入第{}个学生的分数:'.format(i+1)))
students.append(student)
# 打印学生信息
print('所有学生的信息:')
for student in students:
print(student)
# 在每个学生的信息里添加身高信息
for student in students:
student['height'] = 185
# 将第二个同学的分数修改为90分
students[1]['score'] = 90
# 删除第三个同学的信息
del students[2]
# 打印修改后的学生信息
print('修改后的学生信息:')
for student in students:
print(student)
```
输入4个学生的信息后,程序会打印所有学生的信息。在每个学生的信息里添加身高信息后,程序将第二个同学的分数修改为90分,然后删除第三个同学的信息,并打印修改后的学生信息。
注意:这里假设输入的学号、分数等都是合法的,没有进行输入的判断和异常处理。完整代码如下:
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)