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
Lynna [10]
3 years ago
15

Make a Backwards Phonebook from a Regular Phonebook

Computers and Technology
1 answer:
Dima020 [189]3 years ago
7 0

Answer:

Code in Python is given. Take note of the instruction in bold font

Explanation:

You will need to update the below two lines in your system based on the file path -

backward_phone_number('F:\\phone_number_input.txt','F:\\phone_number_output.txt')

def backward_phone_number(input_file,output_file):

   ph_num_dictionary={}

   entries=[]

   #########################################################

   with open(input_file,'r') as read_file:

       entries=read_file.readlines()[1:]

   for entry in entries:

       ph_num_name=entry.split()

       ph_number=ph_num_name[1].strip()

       name=ph_num_name[0].strip()

       if ph_num_dictionary.get(ph_number)==None:

           name_list=[name]

           ph_num_dictionary[ph_number]=name_list

       else:

           ph_num_dictionary.get(ph_number).append(name)

   #########################################################

   ph_num_dictionary = dict(sorted(ph_num_dictionary.items(),key=lambda pair:pair[0]))

   with open(output_file,'w+') as write_file:

       write_file.write('Telephone Number\tName\r\n')

       for num,name in ph_num_dictionary.items():

           if len(name)==1:

               write_file.write(num+'\t'+name[0]+'\r\n')

           else:

               name.sort()

               for person in name:

                   write_file.write(num + '\t' + person + '\r\n')

backward_phone_number('F:\\phone_number_input.txt','F:\\phone_number_output.txt')

You might be interested in
write an application to presell a limited number of cinema tickets. each buyer can buy as many as 4 tickets. No more than 100 ti
Rus_ich [418]

Answer:

The program for this question can be given as:

Program:

import java.util.*;  //import package

public class TicketSeller  //define class

{

public static void main(String ar[])  //main method

{

int totalTickets=100,userCount=0,remainingTickets=100,numTickets; // varaibale

try           //try block

{

Scanner ob= new Scanner(System.in);  //input by user

System.out.println("Total Tickets:"+totalTickets);

while(remainingTickets!=0)          //loop

{

System.out.print("Enter no of Tickets to buy:");      //message.

numTickets=ob.nextInt(); //taking input

if(numTickets<=4)         //conditional statements.

{

if(remainingTickets>=numTickets)

{

remainingTickets=remainingTickets-numTickets;              //calculate remainingTickets

userCount++;

System.out.println("remaining tickets : "+remainingTickets+" user :"+userCount);      

}

else

{

System.out.println("Invalid Input");

}

}

else

{

System.out.println("Invalid Input");

}

}

}

catch(Exception e)            //catch block.

{

}

}

}

Output:

Total tickets:100

Enter no of Tickets to buy: 4

Remaining tickets : 96 User :1

Enter no of Tickets to buy: 4

Remaining tickets : 92 User :2

Enter no of Tickets to buy: 4

Remaining tickets : 88 User :3

.

.

.

Enter no of Tickets to buy: 4

Remaining tickets : 0 User :25

Explanation:

In the above Program firstly we import the package for the user input. Then we declare the class that is (TicketSeller) given in question. In this class we declare the main method in the main method we declare the variable that is totalTickets, userCount, remainingTickets and numTickets .Then we use the exception handling. we use this for providing the validation from the user side that users don't insert value less the 4. In the exception handling, we use the multiple catch block with try block. Then we input from the user and calculate the values and in the last, we print all the values.

8 0
3 years ago
Convert the decimal number 164 into the equivalent 8 bit binary number. ​
umka2103 [35]

Answer:

10100100

Explanation:

8 bit system consists of 8 bits or 8 positions and each of them can have binary value (0 or 1).

Each bit is equivalent to a certain power of number 2. Important to know is that you read these bits from right to left.

So, this means that the bit furthest to the right has the value of 2^0, which is 1. The bit to the left has the value of 2^1, which is 2. Next one is 2^2, which is 4 etc. This means that the bit furthest to the left has the value of 2^7, which is 128.

The bit has this potential value only if value 1 if is in its position. If the value is 0 then, regardless of position, value of the bit is 0.

Decimal value of the number is calculated when we add all the values of the bits marked with 1.

So, we're dealing with number 164. We already said that leftmost bit has the value of 128 if it's marked with 1:

1 0 0 0 0 0 0 0 = 128

Next bit has the value of 64, but 128+64 would exceed the value of our number, so the second leftmost bit remains 0.

Next bit has the value of 32, 128+32 is 160, which is less then our number, so we mark the third bit with 1:

1 0 1 0 0 0 0 0 = 160

Similarly, we continue down the line. We only need 4 to reach the value of our number, so we'll mark with 1 the bit that has the value of 4, which leaves us with the solution:

1 0 1 0 0 1 0 0 = 164

7 0
3 years ago
What is the benefit of making an archive folder visible in the Outlook folder list?
Rufina [12.5K]

Answer:

a

Explanation:

5 0
2 years ago
________ tells users how to use software and what to do if software problems occur.
vitfil [10]

Answer:

Documentation tells users how to use software and what to do if software problems occur.

Explanation:

Documents and Standard Operating Procedures (SOPs) help users use the software that they want to use. This is an advantage to whoever is selling the software so that they don't receive customer complaints and people continue to buy their product.

4 0
1 year ago
This function whose primary purpose is to display information to the user can only display one value at a time.
Leya [2.2K]

Answer:

False

Explanation:

The functions that was made for display content can get  arguments of different type e.g. (Int, string, Array, Objects) and if you want to display n values you only have to check the syntax of your programming language to separate one of each other

# Python example

a = "Hello-"

b = "World"

c = 10

print(a,b,c)

#Out: Hello-World10

I hope it's help you.

4 0
3 years ago
Other questions:
  • What is a directory server?
    5·1 answer
  • Computer programmers often use binary codes (strings of 1s and 0s) to write programs for computers. These codes are then changed
    6·1 answer
  • Digital libraries are often available to students and/or employees at colleges, schools, and BLANK institutions.
    15·1 answer
  • What is the maximum transmission speed for bluetooth v3 and v4 devices?
    12·1 answer
  • The continue statement _________.
    11·1 answer
  • Which of the following statements is false? a. InputStream and OutputStream are abstract classes for performing byte-based I/O.
    7·1 answer
  • In an oblique drawing, which lines can be measured accurately, if there is no foreshortening?
    10·1 answer
  • A personal computer (pc) or ____ is a small computer system designed to be used by one person at a time.
    12·1 answer
  • Suggest three ways in which celebrating an occasion influences food choices?
    10·2 answers
  • 2.Some artists look for ways to extend copyright for longer than the laws normally allow. Why do they do this?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!