1

Give a problem statement that requires you to develop a Python program that meets the following...

Question

Give a problem statement that requires you to develop a Python program that meets the following...

Give a problem statement that requires you to develop a Python program that meets the following requirements

  • (2 EC points) The program reads data from a text file and then assigns it to a string variable
  • (2 EC points) The program defines and calls at least one function other than main()
  • (2 EC points) The program uses a multi-way branch (if, followed by a number of elifs, followed by else)
  • (2 EC points) The program uses a loop (for loop or while loop)
  • (2 EC points) The program modifies the data that it has read from the text file, and then saves the modified data back out to the text file before terminating

Answers

Code:

#Code to change all 4 character words to #### and 5 character words to @@@@@ 6 character words to !!!!!!   def fun(x):                    ls=x.split(" ")          z=[]          st=""                  for i in ls:                  if len(i)==4:             z.append("####")                      elif len(i)==5:             z.append("@@@@@@")                  elif len(i)==6:             z.append("!!!!!!")                  else:             z.append(i)                  for i in z:                  st=st+i+" "          return st                               f = open("a.txt", "r") x=f.readline() f.close()    z=fun(x)   text_file = open("a.txt", "w") n = text_file.write(z) text_file.close()  print("The text has been changed and stored in a.txt")

Output:

a.txt before executing

Run Debug Share Save beauty Language Python 3 main.py a.txt Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiu

a.txt after executing

19 Run Debug Stop Share Save {} Beautify Language Python 3 main.py a.txt @@@@@@@@@@@@@@@@@@ sit #### consectetur adipiscing #

Console output:

53 54 print(The text has been changed and stored in a.txt) The text has been changed and stored in a.txt ... Program finish

1596046243176_image.png


Similar Solved Questions

1 answers
ID: A Exam 3 Multiple Choice Identify the choice thar best completes the worawer the question...
ID: A Exam 3 Multiple Choice Identify the choice thar best completes the worawer the question 1. Le Chatelier's principle states that a. Only exothermic reactions can reach chemical equilibrium b. If a chemical equilibrium is disturbed, the system will try and reestablish equilibrium c. If a che...
1 answers
12. A population data set has mean -2 and standard deviation ơ-11. Find the minimum proportion...
12. A population data set has mean -2 and standard deviation ơ-11. Find the minimum proportion of observations in the data set that must lie: a. between -0.2 and 4.2; b. between -1.3 and 5.3....
1 answers
Presented here are liability items for Marin Inc. at December 31, 2022. Accounts payable Notes payable...
Presented here are liability items for Marin Inc. at December 31, 2022. Accounts payable Notes payable (due May 1, 2023) Bonds payable (due 2026) Unearned rent revenue Discount on bonds payable $141,300 FICA taxes payable $7,020 18,000 Interest payable 36,000 810,000 Notes payable (due 2024) 72,000 ...
1 answers
The notes payable are to banks, and the interest rate on this debt is 10%, the...
The notes payable are to banks, and the interest rate on this debt is 10%, the same as the rate on new bank loans. These bank loans are not used for seasonal financing but instead are part of the company's permanent capital structure. The long-term debt consists of 30,000 bonds, each with a par ...
1 answers
Q.1. NCCAM partnered on a telephone survey of over 1,000 people aged 50 and older in...
Q.1. NCCAM partnered on a telephone survey of over 1,000 people aged 50 and older in 2010. Just over half of those surveyed reported using complementary and alternative medicine and over a third take some type of herbal product or dietary supplement. With what organization did NCCAM/NCCIH partner on...
1 answers
Campbell, a single taxpayer, earns $400,000 in taxable income and $2,000 in interest from an investment...
Campbell, a single taxpayer, earns $400,000 in taxable income and $2,000 in interest from an investment in the State of New York bonds. (Use the U.S. tax rate schedule). Required: If Campbell earns an additional $15,000 of taxable income, what is her marginal tax rate on this income? What is her m...
1 answers
1. Describe the six levels of leadership 2. Describe strategies that enhance personal leadership. 3. Describe...
1. Describe the six levels of leadership 2. Describe strategies that enhance personal leadership. 3. Describe the AIM Leadership Model. 4. Determine the reasons and benefits for creating teams 5. Describe the importance of knowledge management 6. Describe how public health leaders work at the commun...
1 answers
MATLAB I need Matlab ouput 4. Solve the following linear set of equations using the script...
MATLAB I need Matlab ouput 4. Solve the following linear set of equations using the script given below. 53 1 1] x) A=1 3 1 X=(x₂ , B={10} [1 1 3] (45) x=zeros(3,1); AB=[A B] n=size(A,1); for i=1:n-1 P=-(AB(+1:end,i)/AB(1,1)) AB(i+1:end,i:end)=AB(i+1:end,i:end)+P*AB(i,i:end) end for i=n:-1:1 x...
1 answers
Need help on this 32. Bought a new car lately? The following table presents the number...
Need help on this 32. Bought a new car lately? The following table presents the number of cars sold by several manufacturers in a recent month. 26.6 Manufacturer Sales (in thousands) General Motors 82.2 Toyota 96.6 Ford 68.4 Chrysler Honda Nissan 78.0 Hyundai Others 159.0 Source: Wall Street Journal...
1 answers
22. (15 points) Assume I found that b- 20 and m-3 in a regression model If...
22. (15 points) Assume I found that b- 20 and m-3 in a regression model If the p value for b was 0.01 and for m was 0.01 write the linear model Given the p value define in part a, if x - 2 what would your model predict for y a. b. Given the p value define in part c, If x - 2 what would your model pr...
1 answers
3. a) Decide whether these alkenes should be described as E or Z. Only write the...
3. a) Decide whether these alkenes should be described as E or Z. Only write the full name if indicated you should. (also give full name) H Br b) Decide whether these arenes should be described as ortho, meta or para. pelom aid Br Br но. CI OH 4. a) Why is it unnecessary to use the cis/t...
1 answers
Consider the two vectors, A = 18i + 39j B = 7.7i - 21.5j What is...
Consider the two vectors, A = 18i + 39j B = 7.7i - 21.5j What is the magnitude of the vector 3A - B? What is the direction of the vector 3A - B?...
1 answers
Theorems prove the following 4.5 Area of circle 1 The area of a circle is a...
Theorems prove the following 4.5 Area of circle 1 The area of a circle is a = πr, wherer is the radius of the circle Hint: Decompose and rearrange the area of a circle into something a little more familiar. 5.3 Parallel lines in Triangle Theorem I Let a ABC be a triangle with points Pand Q be poi...
1 answers
Consider this reaction: tempe CHOWE HY CH2OH - + Br—Br H3C01 The mechanism proceeds through a...
Consider this reaction: tempe CHOWE HY CH2OH - + Br—Br H3C01 The mechanism proceeds through a first cationic intermediate, intermediate 1. Nucleophilic attack leads to intermediate 2, which goes on to form the final product. In cases that involve a negatively charged nucleophile, the attack of...
1 answers
Which is the major product obtained from bromination of m-t-butylanisole with Br2 / FeBr3? .-Bu t-Bu...
Which is the major product obtained from bromination of m-t-butylanisole with Br2 / FeBr3? .-Bu t-Bu A 8r Br -Bu OB 1.Bu -Bu OD Br...
1 answers
Determine the missing variable and the compressibility coeficient Z Substance pressure Te...
Determine the missing variable and the compressibility coeficient Z Substance pressure Temperature Molar Volume z n-butane 25 bar 510k Nitrogen 5 bar 3.5 dm3/mol Toluene 380k 0.1m3/mol using all of this methods a) the equation of state foe ideal gases b)...
1 answers
A loss of 0.6 mg of Zn occurs in the course of an analysis for that...
A loss of 0.6 mg of Zn occurs in the course of an analysis for that element. Calculate the percent relative error due to this loss if the mass of Zn in the sample is 40 mg. Percent relative error 120 mg. Percent relative error 300 mg. Percent relative error 500 mg. Percent relative error...

-- 0.012072--