Write a function to append lines to a file

Assignment Help Computer Engineering
Reference no: EM132113580

Python programming

Start a new file named defs.py

Write the code to create a function, that when called would ask the user how many lines they would like from the file. Read that many line in from bibfile.txt and print them. Test the code.

Write a new function like the above, but this time would take all of the lines and write them to a file named out.txt.

Write a function to append lines to a file. Do this in a loop that would allow the user to continue adding lines to a file until they enter the letter q.

Open a new file named testClass.py. Create a class named ask. Have this class when called print the words "Good Morning". Go back to the defs.py file and write a function that when called will instantiate a member of the ask class, you can call him fred, and then call the method to have fred print the phrase.

here is what I have so far I am stuck

i = int(input('Please enter how many lines do you want from bibfile to print: '))
f = open("bibfile.txt","r")
while i > 0:
out = f.readline()
print(out)
i = i - 1
f.close()

def print():
i = int(input('Please enter how many lines do you want from bibfile to print: '))
f = open("bibfile.txt","r")
w = open("out.txt", "w")
while i > 0:
out = f.readline()
w.write(out + "\n")
i = i - 1
f.close()
print()

def app():
i = int(input('Please enter lines you would like to append to out.txt press q to end'))
o = open("out.txt", "a")
while i in "q":

app()

Reference no: EM132113580

Questions Cloud

Asks the user for the number of males and number of females : Write a program that asks the user for the number of males and the number of females registered in a class using two separate inputs.
Mean anxiety score in elementary school children : The mean anxiety score in elementary school children is 14.55. A researcher wants to know if children of anxious parents are more anxious than the average child
Write a program that counts how often each word occurs : Write a program that counts how often each word occurs in the supplied text file mary.txt.
What is the probability that the coin you picked is the fair : Given this information, what is the probability that the coin you picked is the fair one?
Write a function to append lines to a file : Write a function to append lines to a file. Do this in a loop that would allow the user to continue adding lines to a file until they enter the letter q.
Write a program to provide information on the height : Write a program to provide information on the height of a ball thrown straight up into the air.
Determine whether the effect of one variable : Suppose you are trying to use linear regression analysis to determine whether the effect of one variable, X1, on another variable, Y, depends upon
Write a program that opens a specified text file : Write a program that opens a specified text file and then displays a list of all the unique words found in the file.
A program that asks the user to enter a word : Write a program that asks the user to enter a word. The program then reads ‘The Raven' by Edgar Allen Poe from a text file, and returns the number of times .

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd