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
An engineer designs a new bus that can drive 30 miles per gallon of fuel. Which of the following was likely one of the client’s
Marat540 [252]
What are the options?
7 0
3 years ago
Read 2 more answers
PLEASE ANSWEAR FAST!!! <br> What does it mean if E˂1
Citrus2011 [14]
Scientific notation is another way to write a number. In scientific notation, the letter E is used to mean "10 to the power of." For example, 1.314E+1 means 1.314 * 101 which is 13.14 . Scientific notation is merely a format used for input and output.
5 0
2 years ago
Why carbon is not used as a semiconductor material​
dmitriy555 [2]
Carbon is not used as semiconductor it has 4 valence electrons in it valence shell but the energy gap is very small it will conduct electricity even at room temperature ,the size of carbon is very small .
8 0
3 years ago
When your hands are on home row, they are resting on the____.
MArishka [77]

Answer:

to which four fingers of each hand return as a base, on a QWERTY keyboard being A, S, D, and F for the left hand and J, K, L, and the semicolon for the right

Explanation:

4 0
3 years ago
Read 2 more answers
A point in the x-y plane is represented by its x-coordinate and y-coordinate. Design the class Point that can store and process
Black_prince [1.1K]

Answer:

#include <iostream>

#include <iomanip>

using namespace std;

class pointType

{

public:

pointType()

{

x=0;

y=0;

}

pointType::pointType(double x,double y)

{

this->x = x;

this->y = y;

}          

void pointType::setPoint(double x,double y)

{

this->x=x;

this->y=y;

}

void pointType::print()

{

cout<<"("<<x<<","<<y<<")\n";

}

double pointType::getX()

{return x;

}

double pointType::getY()

{return y;

}

private:

   double x,y;

};

int main()

{

pointType p2;

double x,y;

cout<<"Enter an x Coordinate for point ";

cin>>x;

cout<<"Enter an y Coordinate for point ";

cin>>y;

p2.setPoint(x,y);

p2.print();

system("pause");    

return 0;

}

5 0
3 years ago
Other questions:
  • Which option is a potential environmental risk of adopting a new technology?
    5·1 answer
  • A flat-plate solar collector is 2 m long and 1 m wide and is inclined 60o to the horizontal. The cover plate is separated from t
    13·1 answer
  • Which of the following requirement statements is an example of a breakdown of the accuracy standard?
    11·1 answer
  • Please answer fast. With full step by step solution.​
    14·1 answer
  • 25 In differential aeration corrosion, rich oxygenated parts are
    14·1 answer
  • What should be your strongest tool be for gulding your ethical decisions making process
    5·1 answer
  • A logic circuit with 3 gates and 2 inputs. The circuit will be read from the final output to the inputs.
    9·1 answer
  • A hammer can be used to see how a mineral breaks. If you observe square chunks of the mineral when broken, what can you conclude
    15·1 answer
  • QUICK ASAP
    5·1 answer
  • A school bus with its flashing red signals on has stopped on a non-divided highway; you must?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!