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]
3 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]3 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
why can planes fly but boats cant and why can boats float but not planes and saying planes fly because of the wind or air is not
Aleksandr-060686 [28]

Answer:

Planes can fly because they have wings and jet turbines and boats cant they need wings and planes cant float because there is to much weight

4 0
3 years ago
Read 2 more answers
Partes de un transformador
BartSMP [9]
Está constituido por dos bobinas de material conductor, devanadas sobre un núcleo cerrado de material ferromagnético, pero aisladas entre sí eléctricamente. ... Las bobinas o devanados se denominan primario y secundario según correspondan a la entrada o salida del sistema en cuestión, respectivamente.
6 0
3 years ago
What properties should the head of a carpenter’s hammer possess? How would you manufacture a hammer head?
BabaBlast [244]

Properties of Carpenter's hammer possess

Explanation:

1.The head of a carpenter's hammer should possess the impact resistance, so that the chips do not peel off the striking face while working.

2.The hammer head should also be very hard, so that it does not deform while driving or eradicate any nails in wood.

3.Carpenter's hammer is used to impact smaller areas of an object.It can drive nails in the wood,can crush  the rock and shape the metal.It is not suitable for heavy work.

How hammer head is manufactured :

1.Hammer head is produced by metal forging process.

2.In this process metal is heated and this molten metal is placed in the cavities said to be dies.

3.One die is fixed and another die is movable.Ram forces the two dies under the forces which gives the metal desired shape.

4.The third process is repeated for several times.

5 0
3 years ago
What is the total inductance of a circuit that contains two 10 uh inductors connected in a parallel?
kolbaska11 [484]

Answer:

  5 microhenries

Explanation:

The effective value of inductors in parallel "add" in the same way that resistors in parallel do. The value is the reciprocal of the sum of the reciprocals of the inductances that are in parallel.

  10 uH ║ 10 uH = 5 uH

The effective inductance is 5 uH.

6 0
3 years ago
Explain the concept of degrees of freedom in terms of physics and mechanics.
Sophie [7]

Explanation:

Step1

Degree of freedom is the number of independent variable which is required to define motion of the system. Degree of freedom is the number of possible motion of the system. Motion can be sliding or rotate. So, there are maximum 6 possible motions of the system, 3 of rotation and 3 of translation. There are 6 maximum possible degrees of freedoms.

Step2

Take an example of slider that is allowed to slide only. So, the slider will have one degree of freedom. Take an example of cylinder which can rotate as well as slide. So, it will have 2 degree of freedom.

6 0
3 years ago
Other questions:
  • What is an Algorithm? *
    5·1 answer
  • It is easy to say that an organization should hire, reward, and dismiss employees based on their character as well as their know
    11·1 answer
  • An air compressor of mass 120 kg is mounted on an elastic foundation. It has been observed that, when a harmonic force of amplit
    13·1 answer
  • CNG is a readily available alternative to
    5·1 answer
  • At a point on the free surface of a stressed body, the normal stresses are 20 ksi (T) on a vertical plane and 30 ksi (C) on a ho
    7·1 answer
  • Source water pollution in Madagascar
    14·1 answer
  • Fill in the blank with the correct response.
    8·1 answer
  • Air enters a compressor operating at steady state at 1.05 bar, 300 K, with a volumetric flow rate of 21 m3/min and exits at 12 b
    11·1 answer
  • What lump sum of money must be deposited in a bank account at present time so that Php 500 monthly can be withdrawn for five yea
    10·1 answer
  • If welding is being done in the vertical position, the torch should have a travel angle of?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!