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
What kind of value should an employee possess when employees are expected to be responsible and fair?
jasenka [17]

Answer:

E self-confidence

Explanation:

6 0
3 years ago
Use superpositions find​
Sunny_sXe [5.5K]

Answer:

no

Explanation:

no

3 0
3 years ago
If a motorist moves with a speed of 30 km/hr, and covers the distance from place A to place B
Sergio039 [100]

Answer:

105 km

Explanation:

The motorist was going 30 km/hr, and it took 3 hours 30 minutes. That's 3.5 hours. 3.5×30=105

5 0
4 years ago
In the High Low Logic Index low levels are bearish and high levels are bullish, generally True False
Irina-Kira [14]

Answer:

True

Explanation:

Logic index is selection of values based on the logical streams. The values appear on the logical array. The levels are determined on the market investment performance. If there are many buyers available in the market the index will be high and the market will be bullish. If there are few or no investors available the market index will be low which means the market is bearish.

8 0
3 years ago
A cubic transmission casing whose side length is 25cm receives an input from the engine at a rate of 350 hp. If the vehicle's ve
Musya8 [376]

Answer:

The surface temperature is 921.95°C .

Explanation:

Given:

   a=25 cm ,P=350 hp⇒P=260750 W

Power transmitted 0.95\times 260750W and remaining will lost in the form of heat.This heat transmitted to air by the convection.

 h=230\frac{W}{m^2-K},\eta =0.95

Actually heat will be transmit by the convection.

In convection Q=hA\Delta T

So P=\Delta T\times Q

0.05\times 260750=230\times0.25^2\(T-15)

T=921.95°C

So the surface temperature is 921.95°C .

6 0
3 years ago
Other questions:
  • The following laboratory tests are performed on aggregate samples:a. Specific gravity and absorptionb. Soundnessc. Sieve analysi
    13·1 answer
  • What are four engineering degrees that can help lead you to becoming an aerospace engineer
    6·1 answer
  • 21.13 The index of refraction of corundum (Al2O3) is anisotropic. Suppose that visible light is passing from one grain to anothe
    5·1 answer
  • Overview In C, a string is simply an array of characters. We have used literal strings all along – the stuff in between the quot
    11·1 answer
  • Consider the following signal:
    8·1 answer
  • Would you ever date a transgender person??
    8·2 answers
  • When you accelerate, the size of the front tire patch becomes____
    15·1 answer
  • Bob would like to run his house off the grid, therefore he needs to find out how many solar panels and batteries he needs to buy
    12·1 answer
  • A single-phase load is located 2800 ft from its source. The load draws a current of 86 A and operates on 480 V. The maximum volt
    10·1 answer
  • What person at the construction worksite keeps workers safe from asbestos exposure?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!