answer.
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
mr_godi [17]
2 years ago
5

Write a program that reads the data from rawdata_2004.txt into a dictionary whose keys are country names and whose values are pe

r capita incomes. Then the program should prompt the user to enter country names and print the corresponding values. Stop when the user enters quit.
Computers and Technology
1 answer:
san4es73 [151]2 years ago
7 0

Answer:

import re

def country_capita():

   #opens file

   file=open("inputfile.txt", "r")

   dictionary=dict()

   #reads line by line

   for line in file.readlines():

       # substitutes for multiple space a single space

       line = re.sub(r"[\s]{2, }", ' ', line)

       list=[]

       #splits line on space

       list=line.split(" ")

       #put into dictionary

       dictionary[list[1]]=list[2]

#   get input

   while True:

       choice=input("Enter the country name or quit to exit: ")

       if choice=="quit":

           break

       elif choice in dictionary.keys():

           print(dictionary[choice])

       else:

           print("Invalid Country")

country_capita()

Explanation:

Using python to code this program. First we, (line 1) import the re module which offers us a set of functions that allows us to search a string for a match. ((line 2) Next we define a function country_capita() that will open rawdata_2004.txt, read the information within line by line and create a dictionary list. The we create a while loop with conditional statements that prompt the user to enter country names, print the corresponding values and stops when the user enters quit.

You might be interested in
Write the 8-bit signed-magnitude, two's complement, and ones' complement representations for each decimal number: +25, + 120, +
pshichka [43]

Answer:

Let's convert the decimals into signed 8-bit binary numbers.

As we need to find the 8-bit magnitude, so write the powers at each bit.

      <u>Sign -bit</u> <u>64</u> <u>32</u> <u>16</u> <u>8</u> <u>4</u> <u>2</u> <u>1</u>

+25 - 0 0 0 1 1 0 0 1

+120- 0 1 1 1 1 0 0 0

+82 - 0 1 0 1 0 0 1       0

-42 - 1 0 1 0 1 0 1 0

-111 - 1 1 1 0 1 1 1 1

One’s Complements:  

+25 (00011001) – 11100110

+120(01111000) - 10000111

+82(01010010) - 10101101

-42(10101010) - 01010101

-111(11101111)- 00010000

Two’s Complements:  

+25 (00011001) – 11100110+1 = 11100111

+120(01111000) – 10000111+1 = 10001000

+82(01010010) – 10101101+1= 10101110

-42(10101010) – 01010101+1= 01010110

-111(11101111)- 00010000+1= 00010001

Explanation:

To find the 8-bit signed magnitude follow this process:

For +120

  • put 0 at Sign-bit as there is plus sign before 120.
  • Put 1 at the largest power of 2 near to 120 and less than 120, so put 1 at 64.
  • Subtract 64 from 120, i.e. 120-64 = 56.
  • Then put 1 at 32, as it is the nearest power of 2 of 56. Then 56-32=24.
  • Then put 1 at 16 and 24-16 = 8.
  • Now put 1 at 8. 8-8 = 0, so put 0 at all rest places.

To find one’s complement of a number 00011001, find 11111111 – 00011001 or put 0 in place each 1 and 1 in place of each 0., i.e., 11100110.

Now to find Two’s complement of a number, just do binary addition of the number with 1.

6 0
2 years ago
1. Discuss why it is so important for all application builders to always check data received from unknown sources, such as Web a
Ivan

Answer:

1. It is so important for all application builders to always check data received from unknown sources before using that data. This is because of the Security related reasons and vulnerabilities .For example the data received might contain harmful hidden viruses.  Web applications are accessed by internet and these are the most vulnerable to attacks by hacker or intruders using harmful data containing malware. This can cause security breaches due to the security flaws or bugs in Web applications. So to overcome such security risks which can cause damage in the Web applications, data from unknown sources should be checked.

Explanation:

2. When the Website is being used and running, there is a room for possible glitches or other bugs and issues. To understand, handle and address  issues successfully, the website operators carefully and consistently patch and configure their systems. The administrators collect the user data which enables them to have enough data in order to make the requisite alterations or improvements in the website. This also helps to improve the website performance. The patching and configuring of systems fix problems in the website which reduces the risk of website damage and the website works smoothly this way. Moreover it identifies vulnerabilities, solve configuration issues and upgrades in website features provide additional capabilities to the website.

8 0
1 year ago
Exponentiation Is a/an operater?​
garik1379 [7]

Answer:

Yes it is

Hope this helps

5 0
1 year ago
Write a function PrintShampooInstructions(), with int parameter numCycles, and void return type. If numCycles is less than 1, pr
Finger [1]

Answer:

public static void PrintShampooInstructions(int numberOfCycles){

       if (numberOfCycles<1){

           System.out.println("Too Few");

       }

       else if(numberOfCycles>4){

           System.out.println("Too many");

       }

       else

           for(int i = 1; i<=numberOfCycles; i++){

               System.out.println(i +": Lather and rinse");

           }

       System.out.println("Done");

   }

Explanation:

I have used Java Programming language to solve this

Use if...elseif and else statement to determine and print "Too Few" or "Too Many".

If within range use a for loop to print the number of times

8 0
2 years ago
Read 2 more answers
During an election year, why would a senator want to determine a mode?
ale4655 [162]

Answer:

To determine which issue is most important to the general public.

Explanation:

Took the Edge assignment!

3 0
1 year ago
Other questions:
  • Of the following tasks, which one CANNOT be easily accomplished with a Wiki? Collaborating Social networking Editing Reading
    13·1 answer
  • Which of the following best describes the concept behind Web 2.0
    5·1 answer
  • Marco makes $65,000 a year as a graphic designer. He makes a charitable donation of $1,000 each year. He also has $5,000 of busi
    12·2 answers
  • What are the pros and cons of using unique closing reserved words on compound statements?
    15·1 answer
  • Gwen recently purchased a new video card, and after she installed it, she realized she did not have the correct connections and
    6·1 answer
  • Using Amdahl’s Law, calculate the speedup gain of an application that has a 60 percent parallel component for (a) two processing
    11·1 answer
  • Create a class named BaseballGame that contains data fields for two team names and scores for each team in each of nine innings.
    12·1 answer
  • You have been employed as a technical consultant to a computer shop chain. You are given the task of creating a short consumer b
    12·1 answer
  • Suppose that a class named ClassA contains a private nonstatic integer named b, a public nonstatic integer named c, and a public
    14·1 answer
  • Chinh wants to have a program print, "Sorry, but that isn’t one of your options" until the user enters the correct information.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!