Lecture 3 — Exercises¶
Overview¶
Solutions to the problems below must be sent to Submitty for grading. A separate file must be submitted for each problem, as practiced in Lab 1.
Problems¶
Which of the following are valid strings? Upload a text file to Submitty that contains just the variable names that are assigned to strings that are correct. For example if only the first two were correct your file would contain s0 on the first line and s1 on the second. Please use the editor in the Spyder IDE to generate the file. Do not use Microsoft Word, Apple Pages or other document editors. They embed extra characters in the text that will make your answer incorrect.
>>> s0 = "Sheldon Cooper's apartment is in Pasedena" >>> s1 = 'This cheese shop's cheese is all gone" >>> s2 = """We are "The Knights of the Round Table" """ >>> s3 = "Toto, I said,\n"We aren't in Kansas, anymore!" >>> s4 = 'Have you seen the "Final Five"'s picture?' >>> s5 = "Have you seen the 'Final Five''s picture?"
Submit a Python file that includes a single line of code that prints 25
'*'
characters followed by 25'+'
characters, with no space in between. It must, of course, use theprint
function. The two characters must appear in your code much less than 25 times - at most three each!Write a program that assigns the value 4 to the variable
x
, the value 2 to the variabley
and then uses exactly threeprint
function calls to generate the output below (four lines, with the second line blank). Theprint
calls must use the variablesx
andy
rather than the values 4 and 2. The trick is to change the assignment of thesep
andend
parameters in the call toprint
. The character4
is the first character on the 1st, 3rd and 4th lines of output.
4 2 4,2 42