您好我的任务是:
创建一个允许用户输入姓名,职称,姓氏,电子邮件和电话号码的系统。提交详细信息后,应将其写入文件。
以字母A-L开头的姓氏应写入一个文件。以M-Z开头的姓氏应该写入第二个文件。用户应该可以选择查看任一文件的内容。此外,它应按字母顺序(按姓氏)输出超过30岁的用户输出详细信息。
我得到的问题是我不知道如何将以字母A-L开头的姓氏写入一个文件,并且应该将以M-Z开头的姓氏写入第二个文件。
import pickle
import time
myFile = open("programingEx.dat","wb")
print("please enter your prefered title: Mr. or Mrs or Miss or Dr.")
Title = (input("enter here:"))
print("please enter your name")
Name = (input("enter here:"))
print("please enter your surname")
surname = (input("enter here:"))
surname1 = []
surname2 = []
if surname[0] == "A" or "C" or "B" or "D" or "E" or "F" or "G" or "H" or "I" or "J" or "K" or "L":
surname1.append(surname)
elif surname[0] == "M" or "N" or "O" or "P" or "Q" or "R" or "S" or "T" or "U" or "V" or "W" or "X" or "Y" or "Z":
surname2.append(surname)
print("hello", Title, surname,)
print("I would like to get your date of birth")
Dob = (input("enter here"))
print("and now I would like to get your phone number and email")
Phone = (input("enter phone here:"))
Email = (input("enter email here:"))
personInfo = [Title,Name, Dob, Phone, Email]
pickle.dump(personInfo,myFile)
pickle.dump(surname1,myFile)
pickle.dump(surname2,myFile)
print("your full name:", Name, surname)
print("your date of birth:", Dob)
print("your phone no.:", Phone)
print("and your email:", Email)
myFile.close()
答案 0 :(得分:1)
而不是写作:
GetMethod(() => ((MyThing)null).DoSomething());
你可以这样测试:
if surname[0] == "A" or "C" or "B" or "D" or "E" or "F" or "G" or "H" or "I" or "J" or "K" or "L":
surname1.append(surname)
elif surname[0] == "M" or "N" or "O" or "P" or "Q" or "R" or "S" or "T" or "U" or "V" or "W" or "X" or "Y" or "Z":
surname2.append(surname)