The following program has a bug. What is it? def get data(ifile): myList = ] %3D for line in ifile: myList.append(line.rstrip() ifile.close() return myList def main(): inFile = open("data.txt", 'r') %3D get_data(inFile) for i in range(len(myList)): print(list[i])
The following program has a bug. What is it? def get data(ifile): myList = ] %3D for line in ifile: myList.append(line.rstrip() ifile.close() return myList def main(): inFile = open("data.txt", 'r') %3D get_data(inFile) for i in range(len(myList)): print(list[i])
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
![The following program has a bug. What is it?
def get data(ifile):
myList = 0
for line in ifile:
myList.append(line.rstrip()
ifile.close()
return myList
def main():
inFile = open("data.txt", 'r')
get_data(inFile)
for i in range(len(myList)):
print(list[i])
main()
O main() does not save the list that get_data() returns; instead it tries to access myList, which is local to get_data() and not defined in main().
In get_data(), the code is trying to append a string to a list.
OIn get_data(), the for-loop doesn't read anything from the file.
O get_data() strips newlines from the end of each line, so main() will print all the data on one line.
O The main() function should not open data.text; it should pass the filename to get_data().](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F909d4e96-ec45-4f89-986e-8cb112f8d100%2Fef9d249f-d0dc-4a4f-af08-69fa4a4ee3fb%2Flyd295_processed.jpeg&w=3840&q=75)
Transcribed Image Text:The following program has a bug. What is it?
def get data(ifile):
myList = 0
for line in ifile:
myList.append(line.rstrip()
ifile.close()
return myList
def main():
inFile = open("data.txt", 'r')
get_data(inFile)
for i in range(len(myList)):
print(list[i])
main()
O main() does not save the list that get_data() returns; instead it tries to access myList, which is local to get_data() and not defined in main().
In get_data(), the code is trying to append a string to a list.
OIn get_data(), the for-loop doesn't read anything from the file.
O get_data() strips newlines from the end of each line, so main() will print all the data on one line.
O The main() function should not open data.text; it should pass the filename to get_data().

Transcribed Image Text:The following input validation code has a bug. What is it? (Line numbers are not part of the code.)
1. again
= True
2. while again:
3.
try:
4.
userChoice = int(input("Please enter your choice (1-5): ")
%3D
5.
if userChoice >= 1 or userChoice <= 5:
6.
again
= False
7.
else:
8.
print("That is not a valid number.")
9.
except ValueError:
10.
print("That is not a number.")
In line 9, the except statement should say except IntError.
O Line 1 should be again = False.
O In line 5, the or should be an and.
O Line 4 should not convert to an int.
In line 6, again = False should be again == False.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps

Recommended textbooks for you

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education

Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY