首页 > 解决方案 > 如何从数组中打印一个单词?

问题描述

我试图打印学生的电子邮件,在底部的 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])

标签: python

解决方案


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]}")

试试这是不是你想要的


推荐阅读