this is a python3 question
every_second_line
Complete the following function according to its docstring description.
Notes:
report is a file open for reading, not a string representing the name of a file.
the method str.strip() may come in handy!
def every_second_line(report):
""" (Open File for reading) -> list of str
Return a list containing every second line (with leading and
trailing
whitespace removed) in report, starting with the first line.
"""
I really got stuck on this question:( could someone please explain to me? thanks in advance!
Hi,
I didn't get exactly what you're asking for, though I guess you need to iterate over every second line and write it in Python 3.
Well, all you need to do is add report.readLine() inside your for loop, that writes lines sequentially.
Assuming your code has even number of lines, use below code -
def every_second_line(report):
list=[]
for line in report:
list.append(line.strip)
report.readLine()
return list
If your code has odd number of lines, use the following piece of
code. This will add the optional argument (None) to the next
method, which tells the compiler to ignore all errors, like
StopIteration or EOFError.
Note that next(report) is used instead of
report.readLine() to iterate over anything and
everything, not just limiting your iteration to files.
def every_second_line(report):
list=[]
for line in report:
list.append(line.strip)
next(report, None)
return list
this is a python3 question every_second_line Complete the following function according to its docstring description. Notes:...
%%%%Python Question%%% Work from the template acrostic.py, which you can find on the ELMS page for this assignment. • In the Generator class, write an __init__() method with two parameters: self and the path to a text file containing one word per line. This method should read the words from the file, strip off leading and trailing whitespace, and store them in a dictionary where each key is a lower-case letter and each corresponding value is a list of words...
I'm a bit confused on how to get this program to run right. Here are the directions: Part 1: Write a Python function called reduceWhitespace that is given a string line and returns the line with all extra whitespace characters between the words removed. For example, ‘This line has extra space characters ‘ ‘This line has extra space characters’ Function name: reduceWhitespace Number of parameters: one string line Return value: one string line The main file should handle the...
This program is part 1 of a larger program. Eventually, it will be a complete Flashcard game. For this part, the program will Prompt the user for a file that contains the questions – use getline(cin, fname) instead of cin >> fname to read the file name from the user. This will keep you in sync with the user’s input for later in the program The first line is the number of questions (just throw this line away this week)...
Python3, write a program, specific information is in the graphs,
I got 7 marks out of 10, you may change my codes to let it gives
correct output,restrications are also on the graph, for loop, in
key word, enumerate,zip,slices, with key word can't be used. All
the information is on the graph, is_shakespeare_play(line) may be a
function given that can check whether is Shakespeare play
Question 2- 10 marks Write the function keep titles short (filename, max charactars) which takes...
Most system administrators would like to know the utilization of their systems by their users. On a Linux system, each user's login records are normally stored in the binary file /var/log/wtmp. The login records in this binary file can not be viewed or edited directly using normal Linux text commands like 'less', 'cat', etc. The 'last' command is often used to display the login records stored in this file in a human readable form. Please check the man page of...
The following are screen grabs of the provided files
Thanks so much for your help, and have a nice day!
My Java Programming Teacher Gave me this for practice before the exam, butI can't get it to work, and I need a working version to discuss with my teacher ASAP, and I would like to sleep at some point before the exam. Please Help TEST QUESTION 5: Tamagotchi For this question, you will write a number of classes that you...
Solve it for java
Question Remember: You will need to read this assignment many times to understand all the details of the you need to write. program Goal: The purp0se of this assignment is to write a Java program that models an elevator, where the elevator itself is a stack of people on the elevator and people wait in queues on each floor to get on the elevator. Scenario: A hospital in a block of old buildings has a nearly-antique...
Read this article. Then write a 250 word response on two of the programs you like the most. Open source business intelligence software 1. BIRT BIRT is an open source BI program that CloudTweaks says is often viewed as the industry standard. BIRT boasts “over 12 million downloads and over 2.5 million developers across 157 countries.” Its users include heavyweights such as Cisco, S1, and IBM (which is also a BIRT sponsor). They also have maturity going for them, as...
Hi, Kindly assist with my project management assignment below using the attached case study Question 1 Update the project charter for the remainder of the project in response to Adams’ memo (lines 241 through 246). Question 2 Prepare a plan for the remainder of the project in response to Adams’ memo (lines 241 through 246). Your answers to the above will be assessed in terms of the level of communication displayed, the insights and inferences drawn, and your ability to...