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
mr_godi [17]
3 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]3 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
Experienced students may serve as mentors if they are at least age 21 and have at least 3 years of post-secondary education. In
AlekseyPX

Answer:

=IF(AND(B2>=21,C2>=3),"Yes","No")

Explanation:

Given

Age: Not less than 21

Post secondary education: Not less than 3 years

Required:

Enter a formula using the IF and AND functions as follows to determine if Kay Colbert is eligible to serve as a mentor

The excel file showing the records is not provided; So, in other to solve this question following assumption will be made

  • Cell B2 represents age
  • Cell C2 represents post secondary education

After giving you the formula using my illustration, all you need to do is to edit the cell names to suit your purpose;

Type the following in Cell L2

=IF(AND(B2>=21,C2>=3),"Yes","No")

<em>Analysis</em>

=: An excel formula must start with =

IF: This shows the function being used

AND: This shows that there are more than one condition in the IF function; all of which must be true

B2>=21,C2>=3: These are the two conditions in the question;

Note that B2 represents the student age and C2 represent the student post secondary education.

"YES": The IF function will return "Yes" without the quotes, if both conditions are true

"NO": Otherwise, the function will return "No" without the quotes

To fill the formula in L3 to L31, all you need to do drag the formula from L2 down to L31

7 0
3 years ago
In real-world environments, risks and their direct consequences will most likely span across several domains. However, in the la
Evgesh-ka [11]
J’mealea oiu toava granega sesis.
8 0
4 years ago
Python uses standard order of operations to evaluate equations. True False
Strike441 [17]

Answer:

False... Can you give me brainliest

Explanation:

6 0
3 years ago
Compare and contrast the various write strategy used in cache technologies<br>​
scZoUnD [109]

Answer:

The abiotic factors are non-living factors in an ecosystem that affect the organisms and their lifestyle. In this case, low temperature and low humidity lead to the conditions that are unfavorable for birds. So, the birds must adapt to these factors by hiding the food in the caches.

Explanation:

8 0
3 years ago
To enhance the readability of your document, select a layout that aligns text ________.
Vilka [71]

Answer:

b. only at the left margin.

Explanation:

It's the most widely accepted layout. MLA format, which is used in most professional settings, aligns the body to the left. Though, the answer may be different depending on the language.

5 0
2 years ago
Read 2 more answers
Other questions:
  • What is an activity that can help you enhance the appearance of your computer’s desktop?
    12·2 answers
  • What is a good project I can do for Artificial Intelligence? It has to be some type of Technology that covers Artificial Intelli
    14·1 answer
  • The presentation ____ determines the formatting characteristics of fonts and colors.
    11·2 answers
  • Type the correct answer in the box. Spell all words correctly.
    12·1 answer
  • ____________ is defined as the set of activities that revolve around a new software product, from its inception to when the prod
    11·1 answer
  • Universal Containers requires that all users add at least one Product Option from the Maintenance Feature to a bundle.
    5·1 answer
  • The purpose of the ________ in a database system is to receive requests from applications and to translate those requests into r
    12·1 answer
  • Why is it important to install updates? Why should you use the Power button on the Start menu instead of the Power button on you
    7·1 answer
  • Why does this happen to me?
    14·1 answer
  • What is Smart Content Profits all about?
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!