0

Hello my assignment is :

Create a system that allows the user to enter their name, title, surname, Dob, email and phone number. Once details are submitted, they should be written to a file.

Surnames that start with the letter A-L should be written to one file. Surnames that start with M-Z should be written to the second file. The user should have the option to view the contents of either file. Also it should output details in alphabetical order (by surname) output details of user over 30.

The problem I am getting is I don't know how to put surnames that start with the letter A-L should be written to one file and surnames that start with M-Z should be written to the second file.

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()
Jdowg
  • 33
  • 5

1 Answers1

1

Instead of writing:

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)

You can test like this:

if "a" <= surname[0].lower() <= "l":
    surname1.append(surname)
if "m" <= surname[0].lower() <= "z":
    surname2.append(surname)
fafl
  • 7,222
  • 3
  • 27
  • 50