Computer Science
Write the output of the following code with justification if the contents of the file "VIVO.txt" are:
"Welcome to Python Programming!"
F1 = open("VIVO.txt", "r")
size = len(F1.read())
print(size)
data = F1.read(5)
print(data)
Answer
The given code opens a file named "VIVO.txt" in read mode and reads its entire content into a variable F1. It then calculates the length of this content using len() and prints the result, which is 30 characters long. However, when it tries to read the next 5 characters from the file using F1.read(5), no characters are left to read since the file pointer is at the end the file. As a result, data remains an empty string.
Output
30
Related Questions
Define candidate key.
Write
push(rollno)andpop()method in Python:push(rollno)— to add roll number in Stackpop()— to remove roll number from StackSimrat has written a code to input an integer and display its first 10 multiples (from 1 to 10). Her code is having errors. Rewrite the correct code and underline the corrections made.
n = int(input(Enter an integer:)) for i in range(1, 11): m = n * j print(m; End = '')Given is a Python string declaration:
voice = "Python for All Learners"Write the output of:
print(voice[20 : : -2])