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
Deffense [45]
2 years ago
13

read a file called filled in with a few sentences or a paragraph. Then write a function called typoglycemia, which scrambles the

letters in the words in the file leaving the first and last characters unchanged and then writes the results to a new file called "scrambled.txt".Save the file
Engineering
1 answer:
sladkih [1.3K]2 years ago
7 0

Answer:

def typoglycemia():

import random

punct = (".", ";", "!", "?", ",")

count = 0

new_word = ""

inputfile = input("Enter input file name:")

with open(inputfile, 'r') as fin:

for line in fin.readlines(): #Read line by line in txt file

for word in line.split(): # Read word by word in each line

if len(word) > 3: # If word length >3

'''If word ends with punctuation, Remove first letter, last letter and punctuation

shuffle the words: Add the removed letters at their respective positions'''

if word.endswith(punct):

word1 = word[1:-2]

word1 = random.sample(word1, len(word1))

word1.insert(0, word[0])

word1.append(word[-2])

word1.append(word[-1])

''' If there is no punctuation mark: Remove first and last letter.

Shuffle the word then add removed letters at their respective position'''

else:

word1 = word[1:-1]

word1 = random.sample(word1, len(word1))

word1.insert(0, word[0])

word1.append(word[-1])

new_word = new_word + ''.join(word1) + " "

''' If word length <3, just append the word and " " to the the previous words'''

else:

new_word = new_word + word + " "

with open((inputfile[:-4] + "scrambled.txt), 'a+') as fout:

fout.write(new_word + "\n")

new_word = ""

You might be interested in
What is a voltage divider circuit and how do you calculate the voltage across one element in a series
Rama09 [41]
Sorry I don’t know myself
6 0
2 years ago
A safety interlock module operates by monitoring the voltage from the
In-s [12.5K]

Answer: its an Ignition coil

8 0
3 years ago
Oxides of nitrogen contribute to the formation of?
Nat2105 [25]

Answer:

B. Acid rain.

C. Photochemical smog.

Explanation:

Oxides of nitrogen contribute to the formation of photochemical smog and acid rain. Photochemical smog is a type of smog produced when ultraviolet light from the sun reacts with nitrogen oxides in the atmosphere while on the other hand, when nitrogen oxide react with the water vapor in the atmosphere forming nitric acid which falls on the earth surface with the help of precipitation.

3 0
3 years ago
An aluminum oxide component must not fail when a tensile stress of 12.5 MPa is applied. Determine the maximum allowable surface
aivan3 [116]

Answer:

1.44 mm

Explanation:

Compute the maximum allowable surface crack length using

C=\frac {2E\gamma}{\pi \sigma_c^{2}} where E is the modulus  of elasticity, \gamma is surface energy and \sigma_c is tensile stress

Substituting the given values

C=\frac {2\times 393\times 10^{9}\times 0.9}{\pi\times (16\times 10^{6})^{2}= 0.001441103 m\approx 1.44mm

The maximum allowable surface crack is 1.44 mm

4 0
3 years ago
The operating sequence to light the main burners on an intermittent pilot system is:______.
11111nata11111 [884]
The pilot valve and spark igniter are energized, the pilot flame is proved, and then the main gas valve is energized.
7 0
1 year ago
Other questions:
  • A reversible refrigerator operates between a low temperature reservoir at TL and a high temperature reservoir at TH . Its coeffi
    12·1 answer
  • Determine displacement (in) of a 1.37 in diameter steel bar, which is 50 ft long under a force of 27,865 lb if elasticity modulu
    5·1 answer
  • Write a static method named fixSpacing that accepts a Scanner representing a file as a parameter and writes that file's text to
    5·1 answer
  • The price of a single item within a group of items is
    8·1 answer
  • The pressure intensity at a point in a fluid is equal in all directions a.true b.false​
    12·1 answer
  • The cost of hiring new employees outpaces the raises for established employees is
    5·1 answer
  • Please help is due tonight
    6·2 answers
  • 1. Using the formula above, complete this task.
    9·1 answer
  • A cylindrical 1045 steel bar is subjected to repeated compression-tension stress cycling along its axis. If the load amplitude i
    10·1 answer
  • What is the difference between a natural and artificial diamond ​
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!