How to write the names that start with A - L to one file and the rest to another?

2024/7/6 11:12:23

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
print (time.strftime("%d/%m/%Y"))from datetime import date
import pickle
import time
print (time.strftime("%d/%m/%Y"))
from datetime import dateprint("Hello welcome to the program")
title = input("Please enter your prefered title")
response = None 
if response not in ("Mr","Mrs","Miss","Dr"):
response = input("Incorrect try again.Please enter your prefered title")
name = input("Please enter your name")
surname =  input("Please enter your surname")
Dob = input("Enter your date of birth in this format: dd/mm/yy")
print("Your initials are:",name[0],surname[0])
fullname = title  + name +" "+ surname
Answer

Check the alphabet-index of the first letter in the string:

    import stringind = string.lowercase.index(surname[0].lower())if ind <= 12: # A-L# Write to A-L fileelse:# Write to other file
https://en.xdnf.cn/q/120726.html

Related Q&A

How is it possible to use a while loop to print even numbers 2 through 100?

I am a beginner and I am stuck on this problem, "Write a python code that uses a while loop to print even numbers from 2 through 100. Hint ConsecutiveEven differ by 2."Here is what I came up …

Issue with buttons not functioning after start of program

I am new and learning python 3.6 and Ive almost completed my first code project. After doing an exhaustive search to resolve my problem I have not been able to find the answer to what I am sure is a si…

explanation of C implementation pythons len function [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 5…

How to compare the attributes start with $ in 2 functions and display match or mismatch

My input file contain attributes if(match($OPTION_EnableDetails, "1") or match($OPTION_EnableDetails_juniper, "1")) {details($juniFileXferStatus,$juniFileXferTimeStamp,$juniFileXfer…

Python comparing elements in two lists

I have two lists:a - dictionary which contains keywords such as ["impeccable", "obvious", "fantastic", "evident"] as elements of the listb - sentences which cont…

Remove all keys that have values of N/A, -, or empty strings [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 2…

Sorting algorithms more efficient than bubble sort [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 7 years ago.Improve…

How can I return the odd numbers of a list, using only recursion in Python? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable…

TypeError: int object is not iterable; Python 2.7

Here is my code:def numbers_in_lists(string):num = int(string)l = list(num)return lstring = 543987When i run it:print numbers_in_lists(string)I have the following error:l = list(num) TypeError: int obj…

Python: Are `hash` values for built-in numeric types, strings standardised?

I came to this question while pondering about the ordering of set, frozenset and dict. Python doesnt guarantee any ordering, and any ordering is coupled to the hash value at some level. But is the hash…