python - 如何从数组中打印一个单词?
问题描述
我试图打印学生的电子邮件,在底部的 while 循环中,我也试图输入学生的电子邮件,但我不知道如何正确地做到这一点。
代码:
array1 = []
numstudents = int(input("How many students are in the class?: "))
for i in range (numstudents):
studentname,studentemail,dayofbrith,monthofbrith,yearofbrith = input("Enter the student name, the
student's email and the date of birth in the form 'name, email, day of birth, month of birth, year
of birth' : ").split("")
array1.append(studentname+studentemail+dayofbrith+monthofbrith+yearofbrith)
if studentname == "stop":
print("")
break
else:
print("")
print(array1)
while True:
email = input("From which student's email you want: ")
if email any in array1[0]:
print("")
print(array1[1])
解决方案
students = []
numstudents = int(input('How many students are in the class?: '))
for _ in range(numstudents):
print("Please enter the following: ")
print("The student's name, The student's email, day of birth, month of birth, year of birth")
students.append(input().split())
target = input("Which studen't email you want: ")
for i in students:
if i[0] == target:
print(f"The student's email is {i[1]}")
试试这是不是你想要的
推荐阅读
- python - Python 全栈应用程序 - python manage.py runserver - 没有这样的文件或目录
- python-3.x - 刷新 tkinter 消息框中的文本
- postgresql - Postgres 表分区没有提高查询速度
- java - iText PdfCopy 创建可编辑的 pdf 文档
- javascript - var fs = require('fs') 之后的代码没有运行
- css - 颜色的过渡是即时的?
- c++ - blobdetector 中的 opencv 3 C++ 功能规范中的错误?
- jquery - 使用 Jquery 发布图片
- python - 在 Python 列表理解中更新 JSON 元素
- python-3.x - 在 python 中解析嵌套的 List 列表和字典