1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Veronika [31]
3 years ago
12

Create a Python program that: Allows the user to enter a person's first name and last name. The user should be able to enter as

many names as they desire. Create a function that takes the first name and last name, puts them together with the last name first, followed by the first name; with the names separated by commas. Take the result from the function, and place the resulting name in a list. Once the user finishes entering names, sort the contents of the list. Write the sorted names from a list into a text file. When you create the text file, allow the user to enter a name for the file to be created. After you finish writing names to the file, close the file and end the program.
Computers and Technology
1 answer:
KIM [24]3 years ago
7 0

Answer:

#main function start

def main():

#list to store names entered by user

name_list=[]

#variable to take input from user to keep rotating the loop and take input from user again and again

ch='y'

fname=""

lname=""

while ch=='y' or ch=='Y':#keep the loop taking input from user till user do not want to enter more

#take input from user

name=[]

fname=input("Enter first name: ")

lname=input("Enter last name: ")

name.append(fname)

name.append(lname)

 

#append the previously input first and last name in main list

name_list.append(name)

ch=input("Do you want to continue: (y/Y for yes)")

#main function end

#get file name from user

filename=input("Enter output file name")

#open file in write mode

file=open(filename,"w")

#keep loop add data in file till main list 'name_list' have

for i in name_list:

#Write data in file

file.write("%s, %s\r\n" % (i[0],i[1]))

#close the file

file.close()

#call main function

main()

Explanation:

input the above code and see output

You might be interested in
What is the definition of physical fitness?
Bond [772]
The answer is A:the body’s ability to be efficient during movement.
5 0
3 years ago
Read 2 more answers
Any two differences between third and fourth generation of computer
Setler [38]

Answer:

Third generation computer use integrated circuit(IC) and it was fast and reliable.

Forth generation computer micro computer were introduced and they were highly reliable and fast.

5 0
2 years ago
Read 2 more answers
The most common size for a brochure is _____.
Juli2301 [7.4K]
3.5X2 cannot be the answer as it too small and not enough information can be put into it. The common size for tri-fold brochures is 8.5X11 or letter size even when 8.5X14 is also a size used it is not the most common size.
6 0
3 years ago
What is an algorithm?
hichkok12 [17]
D. Both A and C. In my opinion though...
8 0
3 years ago
Whitespace consists of all of the following, except
nydimaria [60]
It is C: COMMAS!!!
i hope i helped you!
4 0
3 years ago
Read 2 more answers
Other questions:
  • Ben buys an Olympus E-PL2 from Sony which starts malfunctioning. When he opts for an exchange, the customer representative says
    11·1 answer
  • Universal Containers are using Salesforce for Order Management and has integrated with an in-house ERP system for order fulfilme
    5·1 answer
  • How to search multiple microsoft word documents?
    15·1 answer
  • In c++
    9·1 answer
  • Write a program that prompts the user to enter the weight of a person in kilograms and outputs the equivalent weight in pounds.
    8·1 answer
  • Once a graph has been created, you would need to start over to make any changes to it?
    5·1 answer
  • What is the definition of digital literacy?
    7·2 answers
  • Both aliases and functions can be used to store commands that can be executed, but functions can also accept positional paramete
    14·1 answer
  • Is the flow of power reversible in a leadscrew?
    11·1 answer
  • Use the function varimp() on the output of train() and save it to an object called imp:_____.
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!