Write a program that reads the input.txt file character by character and writes the content of the input file to output.txt with capitalize each word (it means upper case the first letter of a word and lowercase remaining letters of the word)

Answers

Answer 1

Answer:

def case_convertfile( file_name):

    with open(" new_file","x") as file:

         file.close( )

    with open("file_name", "r") as txt_file:

     while True:

            word = txt_file.readline( )

            word_split= word.split(" ")

            for word in word_split:

                  upper_case = word.uppercase( )

                  file= open("new_file","w+")

                  file= open("new_file","a+")

                  file.write(upper_case)

     txt_file.close( )

     file.close( )

Explanation:

This python function would open an existing file with read privilege and a new file with write and append privileges read and capitalize the content of the old file and store it in the new file.


Related Questions

Write a method named coinFlip that accepts as its parameter a string holding a file name, opens that file and reads its contents as a sequence of whitespace-separated tokens. Assume that the input file data represents results of sets of coin flips. A coin flip is either the letter H or T, or the word Heads or Tails, in either upper or lower case, separated by at least one space. You should read the sequence of coin flips and output to the console the number of heads and the percentage of heads in that line, rounded to the nearest whole number. If this percentage is 50% or greater, you should print a "You win!" message; otherwise, print "You lose!". For example, consider the following input file: H T H H T Tails taIlS tAILs TailS heads HEAds hEadS For the input above, your method should produce the following output: 6 heads (50%) You win!

Answers

Answer:

Here is the JAVA program:

import java.io.*;

import java.util.*;

public class Main {

public static void main(String[] args) throws FileNotFoundException{ //the start of main() function body, it throws an exception that indicates a failed  attempt to open the file

Scanner input = new Scanner(new File("file.txt")); //creates a Scanner object and a File object to open and scan through the file.txt    

coinFlip(input);    } //calls coinFlip method

public static void coinFlip(Scanner input) { //coinFlip method that accepts as its parameter a string input holding a file name

while(input.hasNextLine()) { //iterates through the input file checking if there is another line in the input file

Scanner scan = new Scanner(input.nextLine()); //creates a Scanner object

int head = 0; // stores count of number of heads

int count = 0; //stores count of  total number of tokens

while(scan.hasNext()) { //iterates through the sequence checking if there is another sequence in the input file

String token= scan.next(); // checks and returns the next token

if (token.equalsIgnoreCase("H")||token.equalsIgnoreCase("Heads")) { //compares H or Heads with the tokens in file ignoring lower case and upper case differences

           head++;                } //if a token i.e. any form of heads in file matches with the H or Heads then add 1 to the number of heads

           count++;            } //increment to 1 to compute total number of counts

double result = Percentage(head, count); //calls Percentage method passing number of heads and total counts to compute the percentage of heads

System.out.println(head + " heads " + "(" + result +"%)"); // prints the number of heads

if(result >= 50.00) { //if the percentage is greater or equal to 50

System.out.println("You win!");} //displays this message if above if condition is true

else //if the percentage is less than 50

{System.out.println("You lose!");}  }    } //displays this message if above if condition is false

public static double Percentage(int h, int total) { //method to compute the percentage of heads

double p = (double)h/total* 100; // divide number of heads with the total count and multiply the result by 100 to compute percentage

return p;    } } //returns result

Explanation:

The program is well explained in the comments mentioned with each line of the above code. I will explain how the method coinFlip  works.

Method coinFlip accepts a string holding a file name as its parameter. It opens that file and reads its contents as a sequence of tokens. Then it reads and scans through each token and the if condition statement:

if (token.equalsIgnoreCase("H")||token.equalsIgnoreCase("Heads"))

checks if the each token in the sequence stored in the file is equal to the H or Heads regardless of the case of the token. For example if the first token in the sequence is H then this if condition evaluates to true. Then the head++ statement increments the count of head by 1. After scanning each token in the sequence the variable count is also increased to 1.

If the token of the sequence is HeAds then this if condition evaluates to true because the lower or upper case difference is ignored due to equalsIgnoreCase method. Each time a head is found in the sequence the variable head is incremented to 1.

However if the token in the sequence is Tails then this if condition evaluates to false. Then the value of head variable is not incremented to 1. Next the count variable is incremented to 1 because this variable value is always incremented to 1 each time a token is scanned because count returns the total number of tokens and head returns total number of heads in the tokens.

Percentage method is used to return the percentage of the number of heads in the sequence. It takes head and count as parameters (h and total). Computes the percentage by this formula h/total* 100. If the result of this is greater than or equal to 50 then the message  You win is displayed otherwise message You lose! is displayed in output.

What is the quick key to highlighting a column?
Ctrl + down arrow
Ctrl + Shift + down arrow
Right-click + down arrow
Ctrl + Windows + down arrow

Answers

The quick key to highlighting a column is the Ctrl + Shift + down arrow. Thus, option (b) is correct.

What is column?

The term column refers to how data is organized vertically from top to bottom. Columns are groups of cells that are arranged vertically and run from top to bottom. A column is a group of cells in a table that are vertically aligned. The column is the used in the excel worksheet.

The quick key for highlighting a column is Ctrl + Shift + down arrow. To select downward, press Ctrl-Shift-Down Arrow. To pick anything, use Ctrl-Shift-Right Arrow, then Ctrl-Shift-Down Arrow. In the Move/Highlight Cells, the was employed. The majority of the time, the excel worksheet was used.

As a result, the quick key to highlighting a column is the Ctrl + Shift + down arrow. Therefore, option (b) is correct.

Learn more about the column, here:

https://brainly.com/question/3642260

#SPJ6

Answer:

its (B) ctrl+shift+down arrow

hope this helps <3

Explanation:

The fact that the speed of a vehicle is lower than the prescribed limits shall relieve the driver from the duty to decrease speed when approaching and crossing an intersection. True or false

Answers

Explanation:

the answer is false ........

The fact that the speed of a vehicle is lower than the prescribed limits shall relieve the driver from the duty to decrease speed when approaching and crossing an intersection is not true.

What is intersection in the traffic rules?

An intersection serves as the point where many lanes cross on the road which is a point where driver is required to follow the traffic rules.

However, the above statement is not true because , a driver can decide not  decrease speed when approaching and crossing an intersection, even though it is a punishable offense in traffic rules.

Read more on traffic rules here: https://brainly.com/question/1071840

#SPJ2

A machine on a 10 Mbps network is regulated by a token bucket algorithm with a fill rate of 3 Mbps. The bucket is initially filled to capacity at 3MB. How long can the machine transmit at the full 10 Mbps capacity

Answers

2+4= this gbhfchgcjdxbhdch is correct

What is resource management in Wireless Communication? Explain its advantages

Answers

Answer:

This is a management system in wireless communication that oversees radio resources and crosstalks between two radio transmitters which make use of the same channel.

Explanation:

Radio Resource Management is a management system in wireless communication that oversees radio resources and crosstalks between two radio transmitters which make use of the same channel. Its aim is to effectively manage the radio network infrastructure. Its advantages include;

1. It allows for multi-users communication instead of point-to-point channel capacity.

2. it increases the system spectral efficiency by a high order of magnitude. The introduction of advanced coding and source coding makes this possible.

3. It helps systems that are affected by co-channel interference. An example of such a system is the wireless network used in computers which are characterized by different access points that make use of the same channel frequencies.

Cloud computing gives you the ability to expand and reduce resources according to your specific service requirement.

a. True
b. False

Answers

Answer:

a. True

Explanation:

Cloud computing can be defined as a type of computing that requires shared computing resources such as cloud storage (data storage), servers, computer power, and software over the internet rather than local servers and hard drives.

Generally, cloud computing offers individuals and businesses a fast, effective and efficient way of providing services.

In Computer science, one of the most essential characteristics or advantages of cloud computing is rapid elasticity.

By rapid elasticity, it simply means that cloud computing gives you the ability to expand and reduce resources according to your specific service requirement because resources such as servers can be used to execute a particular task and after completion, these resources can then be released or reduced.

Some of the examples of cloud computing are Google Slides, Google Drive, Dropbox, OneDrive etc.

Other Questions
In the figure below, angle y and angle x form vertical angles. Angle x forms a straight line with the 50 angle and the 40 angle. A straight line is shown and is marked with three angles. The first angle measures 50 degrees. The second angle measures 60 degrees. The third angle is labeled x. The line between the 40 degree angle and angle x extends below the straight line. The angle formed is labeled angle y. Write and solve an equation to determine the measure of angle y. Which of the following "Progressive Amendments" gave women the right to vote? A. 16th Amendment B. 17th Amendment C. 18th Amendment D. 19th Amendment What is a21 of the arithmetic sequence for which a7=19 and a10=28? A. -35 B. 35 C. -58 D. -61 what number must be added to the sequence of 7,13 and 10 to get an average of 13 When titrating a strong acid with a strong base, after the equivalence point is reached, the pH will be determined exclusively by: Select the correct answer below: A) hydronium concentration B) hydroxide concentration C) conjugate base concentration D) conjugate acid concentration Please answer this correctly without making mistakes Read the excerpt from "Children of the Drug Wars." By sending these children away, "you are handing them a death sentence," says Jos Arnulfo Ochoa Ochoa, an expert in Honduras with World Vision International, a Christian humanitarian aid group. This abrogates international conventions we have signed and undermines our credibility as a humane country. It would be a disgrace if this wealthy nation turned its back on the 52,000 children who have arrived since October, many of them legitimate refugees. The underlined words and phrases have strong negative connotations. How do they support the author's purpose? Tybalt: This, by his voice, should be a Montague. Fetch me my rapier, boy. What! dares the slave Come hither, cover'd with an antick face, To fleer and scorn at our solemnity? Now, by the stock and honour of my kin, To strike him dead I hold it not a sin. Romeo and Juliet, William Shakespeare How does Tybalts relationship with Romeo affect his reaction to Romeo being at the party? He thinks Romeo is there to insult his family because of the ongoing feud. He thinks Romeo is there to wear a silly mask and dance because he is an entertainer. He thinks Romeo is there to work as a servant, because they are not equals. He thinks Romeo is there to challenge him to a fight because they hate each other. 11. Samantha was asked to measure out 10 g of salt in a lab. She mistakenly measures out 15 g instead. Calculatethe percent error. Make sure your answer has the correct number of significant figures! What has a greater influence on protein levels? A. Protein degradation has a greater influence because they are denatured faster than the cell can produce them B. mRNA destroyer concentration has a greater influence because it is destroying mRNA before proteins can even be produced C. mRNA destroyer concentration has a greater influence because mRNA is destroyed right after the proteins are produced D. Protein degradation has a greater influence because outside factors like antibiotics can cause it, and it is difficult to recover from what is the location in the base interface of the link tocreate a table using wizard?pls Answer me. I'll make as BRIANLIST. Stephanie is twice as old as her sister Rosa. If Stephanie is 18 years old, how old is Rosa? 3. Which plants are usually the first to grow during secondary succession?A fernsBlichensCweedsD trees Question 18(Multiple Choice Worth 2 polnis)When riding your skateboard you crash into a curb, the skateboard stops, and you continue moving forward. Which law ofmotion is being described in this scenario?O Law of Universal Gravitationo Newton's Second Law of Motiono Law of Conservation of Energyo Newton's First Law of Motion A physiological psychologist has performed an experiment to determine if a particular drug, smartozine, affects maze learning in rats. Three groups of 8 rats each are injected with one of three different doses of smartozine, while a fourth group of 6 rats is injected with a saline solution as a control. After the injection, rats in all four groups are timed in how long it takes them to learn to traverse a maze. The results of the experiment are presented below. Did smartozine affect how quickly the rats learned the maze. Use a level of significance of.05 SSB 610 SSW = 1742 What is the critical value of F for this situation? how will a new front desk manager address a problem of lateness in a hotel. a businessman bought three machines at rs 5400 each and spent 4000 on rearing and sold the machines for Rs Rs 7000 each, how much profit didi he make? In triangle ABC, ABC=70 and ACB=50. Points M and N lie on sides AB and AC respectively such that MCB=40 and NBC=50. Find mNMC. If you have a little air in a balloon, find the volume of the balloon if the mass is 0.6 g and the density of the air is 0.0012 g / mL Richards Parker is pis alter ego in a well constructed essay of 400 500 words explain how Richard Parker helps pi to survive his 227day ordeal On the lifeboat