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
A steel rule can be used to check for
MAXImum [283]
I THINK THE ANSWER IS B BUT IM NOT SURE OK BYE
3 0
3 years ago
Plane wall of material A with internal heat generation is insulated on one side and bounded by a second wall of material B, whic
viktelen [127]

Sorry❤

Have a nice day ✨

8 0
3 years ago
What is the purpose of a gusset or gusset plate used in the construction and repair of aircraft structures?
spin [16.1K]

Answer:

To join and reinforce intersecting structural members

Explanation:

The purpose of a gusset or gusset plate used in the construction and repair of aircraft structures is to join and reinforce intersecting structural members

5 0
2 years ago
9.21 LAB: Sorting TV Shows (dictionaries and lists) Write a program that first reads in the name of an input file and then reads
natka813 [3]

The following code or the program will be used

<u>Explanation:</u>

def readFile(filename):

   dict = {}

   with open(filename, 'r') as infile:

       lines = infile.readlines()

       for index in range(0, len(lines) - 1, 2):

           if lines[index].strip()=='':continue

           count = int(lines[index].strip())

           name = lines[index + 1].strip()

           if count in dict.keys():

               name_list = dict.get(count)

               name_list.append(name)

               name_list.sort()

           else:

               dict[count] = [name]

           print(count,name)

   return dict

def output_keys(dict, filename):

   with open(filename,'w+') as outfile:

       for key in sorted(dict.keys()):

           outfile.write('{}: {}\n'.format(key,';'.join(dict.get(key))))

           print('{}: {}\n'.format(key,';'.join(dict.get(key))))  

def output_titles(dict, filename):

   titles = []

   for title in dict.values():

       titles.extend(title)

   with open(filename,'w+') as outfile:

       for title in sorted(titles):

           outfile.write('{}\n'.format(title))

           print(title)

def main():

   filename = input('Enter input file name: ')

   dict = readFile(filename)

   if dict is None:

       print('Error: Invalid file name provided: {}'.format(filename))

       return

   print(dict)

   output_filename_1 ='output_keys.txt'

   output_filename_2 ='output_titles.txt'

   output_keys(dict,output_filename_1)

   output_titles(dict,output_filename_2)  

main()

8 0
3 years ago
When a circuit has a supermesh, you write two equations: the supermesh constraint equation and the supermesh KVL equation. You h
givi [52]

Explanation:

Note: Refer the diagram attached

Apply KVL around i_{z} loop

\begin{aligned}&5 k \left(i_{z}-i_{y}\right)+2 v_{\Delta}=0\\&5000\left(i_{z}-i_{y}\right)+2 v_{\Delta}=0 \quad \ldots \ldots(1)\end{aligned}

From the circuit, \(v_{\Delta}\) can be expressed using ohm's law as,\\\(v_{\Delta}=(1 k ) i_{y}\)\(v_{\Delta}=1000 i_{y}\)

3 0
4 years ago
Other questions:
  • System grounding on a power system means electrically connecting the __?__ of every wye-connected transformer or generator to ea
    12·1 answer
  • Anyone have 11th grade engineering on odyssey ware?
    8·1 answer
  • ¿Cuándo se formarán cristales en una mezcla que se está evaporando?
    9·1 answer
  • A safety interlock module operates by monitoring the voltage from the
    12·1 answer
  • Where you live might affect how often you change your cabin air filter.<br> True<br> False
    8·1 answer
  • A heat engine operates between 2 reservoirs at TH and 18oC. The heat engine receives 17,000 kJ/h from the high temperature reser
    10·1 answer
  • If you have 300 skittles in a bag and you need to have 28 percent yellow. How many yellow skittles would you have to make a mini
    11·1 answer
  • Once you get the answer correct first i will mark you brainliest!!
    15·2 answers
  • Does anyone know what this is​
    10·2 answers
  • ) In a disk test performed on a specimen 32-mm in diameter and 7 mm thick, the specimen fractures at a stress of 680 MPa. What w
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!