10-13 Basics
Python proficiency questions.
-
Suppose
xis an object of classCC. What method is run bystr(x)? -
Give an efficient way to remove the trailing newlines from an array of strings read from a file.
['the\n','mouse\n','went\n','up\n','the\n','clock\n'] -
When you read the lines from a file, you get to following:
['\n','\n','\n','NVERT 2\n','0 1\n','\n']There are a bunch of blank lines that should be ignored. What do you recommend to do about this annoyance? Note: totally empty lines are almost as annoying as lines with newlines. Write code show how you plan to handle the problem, beginning with
f = open("demo.txt","r"). -
(
fnsr) A filefconsists of two numbers and a string. Write a functionfnsrto determine if the sum of the two numbers equals the number of characters in the string. the input tofnstris the already open file returned fromopen. The output is a boolean. Examples for True and False.5 8 abcdefghijklmnopqrstuvwyzabcdefghinjlmno 1 3 four