Python:
1) Consider the following code segment:
try : inputFile = open("lyrics.txt", "r") line = inputFile.readline() print(line) _____________________ print("Error")
What should be placed in the blank so that the program will print Error instead of crashing if an exception occurs while opening or reading from the file?
Group of answer choices
a- except RuntimeError :
b- except EnvironmentError :
c- except IOError :
d- except IndexError :
2) Consider the following code segment:
line = "hello world!" parts = line.split() print(parts)
What is displayed when this code segment runs?
Group of answer choices
a- hello,world!
b- hello world!
c- "hello", "world!"
d- ["hello", "world!"]
3) After executing the following code snippet, what part is the file object?
infile = open("input.txt", "r")
Group of answer choices
a- infile
b- "input.txt"
c- "r"
d- input
4) In the following code snippet, what happens if the "output.txt" file already exists?
outfile = open("output.txt", "w")
Group of answer choices
a- Any new data is appended to the end
b- The existing file is emptied
c- Nothing, this statement is ignored
d- An error message is displayed
5) Which character encoding standard uses sequences of between 1 and 4 bytes to represent a huge number of different characters?
Group of answer choices
a- ASCII
b- CSV
c- Extended ASCII
d- UTF-8
Answer 1
**********
c- except IOError :
Answer 2
**********
d- ["hello", "world!"]
Answer 3
**********
a- infile
Answer 4
*********
b- The existing file is emptied
Answer 5
**********
d- UTF-8
if you have any doubt then please ask me without any hesitation in
the comment section below , if you like my answer then please
thumbs up for the answer , before giving thumbs down please discuss
the question it may possible that we may understand the question
different way and we can edit and change the answers if you argue,
thanks :)
Python: 1) Consider the following code segment: try : inputFile = open("lyrics.txt", "r") line = inputFile.readline()...
Python: 1) What output is generated by the following code segment? table = [["T", "U", "V"], ["W", "X", "Y"]] print(table[0]) Group of answer choices a- T b- ["T", "W"] c- ["T", "U", "V"] d- [["T", "U", "V"], ["W", "X", "Y"]] 2) Consider the following code segment: values = [4, 12, 0, 1, 5] print(values[1]) What is displayed when it runs? Group of answer choices a- 0 b- 1 c- 4 d- 12 3) Consider the following code segment: x =...
Hello I have a file containing a pin, account name, and balance all on one line. I need to append the pin to the list and the name plus balance to the dictionary. Here is my code for the function below. def atm(inf): infile = open(inf,"r") bigbank={} pin=[] for line in infile: if line[0:3] in infile: pin.append(line[0:3]) #bigbank.update(line[4:])#appendDict????? else: #line(4,len(line)) in infile: name,score = line.split(":") bigbank[name] = int(score) return (pin,bigbank) print(pin,bigbank) inf = input('Insert?') #call the function pin1, bigbank1 =...
What code should be added to the end of the following code segment to ensure that inFileis always closed, even if an exception is thrown in the code represented by . . . ? inFile = open("test.txt", "r") try : line = inFile.readline() . . . Question 25 options: A) inFile.close() B) always : inFile.close() C) ensure : inFile.close() D) finally :
use python IDEL Please highlight the answer Problem 2 Files. Since almost all data can be stored in files, knowing how to use files in programs is invaluable. Today you will practice with opening a file for reading, writing and editing using the Python interpreter. Do not type messages in red into Python shell Question 14 0.5 pts create a new file mytext.txt for >>>f1 = open("mytest.txt","w+") writing & reading >>>f1.write("hello\n") >>>for i in range(5): f1.write(str(i) + "\n") >>>f1.readlines() record...
IT PYTHON QUESTION1 Consider the following Python code, where infile.txt and outfile.txt both exist in the current directory 'z' ) 。1d = open ( ' infile. txt ' , for line in old: new.write (line) new.write') ne«.close () old.close) Which of the following options best describes the purpose or outcome of this code? O A copy of the file infile.txt is made (except in double line spacing) and saved as outfile.txt in the current directory. O A copy of the...
Python Error: Writing a program to complete the following: Prompt the user for the name of an input file. Open that file for input. (reading) Read the file using a "for line in a file" loop For each line, o print the line and compute and print the average word length for that line. Close the input file Sample output: MY CODE IS WRONG AND NEED HELP CORRECTING IT!!! ------------------------------------------------------------------------------------------------------------------------ DESIRED OUTPUT: Enter input file name: Seasons.txt Thirty days hath September...
SQU PORTA ATTENDANCE ENCHISE EN sed 100 bon Python's error handling process includes the finally clause In the following code snippet, when is the finally clause executed inputFile = open("lyrics.txt", "-") try: line - inputFile.readline() words line.split() print (words) finally input file.close() Select one a. Only when there is an error opening the file b. Only when there is an error reading the file c The finally clause is never executed in this example d. The finally clause is always...
use python IDEL Please highlight the answer 1 ווCIוסטIT Errors and Exceptions. There are two main types of errors: syntax errors and runtime errors. Syntax errors are detected by the Python interpreter before the program execution during the parsing stage (parsing is a process, during which the Python interpreter analyzes the grammatical structure of the program). Runtime errors are errors in a program that are not detected by the Python interpreter during its parsing stage. They are further divided into...
use python IDEL Please highlight the answer Problem 1 Errors and Exceptions. There are two main types of errors: syntax errors and runtime errors. Syntax errors are detected by the Python interpreter before the program execution during the parsing stage (parsing is a process, during which the Python interpreter analyzes the grammatical structure of the program). Runtime errors are errors in a program that are not detected by the Python interpreter during its parsing stage. They are further divided into...
Python Problem Hello i am trying to finish this code it does not save guesses or count wrong guesses. When printing hman it needs to only show _ and letters together. For example if the word is amazing and guess=a it must print a_a_ _ _ _ not a_ _ _ _ and _a_ _ _ separately or with spaces. The guess has a maximum of 8 wrong guesses so for every wrong guess the game must count it if...