Question
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
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 + " ") 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()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started