for j in range(7, 10):
print(j, end=" ")
7 8 9
This is an individual-effort assignment: the code you submit must be written by you; it may not be written by another person nor may it be generated with an algorithm.
Put all files for this assignment in your problem_set0
folder and submit them as a zip file named problem_set0.zip
.
This assignment is scored out of 100. There are more than 100 possible points, but the maximum score you can earn on this assignment is 100. Do not get stuck on any one problem, but do complete as many problems as you can.
Pay close attention to the format of output, names of functions, names of files, and names of variables. These errors are common reasons for losing points on problems that otherwise would have been full credit.
Leading (very beginning of output) and trailing (very end output) spaces and newline characters in printed output are ignored during grading.
Write a function print_grid
that takes an integer argument size
and prints a number grid that conforms to the following pattern based on the value of size
:
print_grid(7)
[ 7 8 9 ]
[ 6 7 8 ]
[ 5 6 7 ]
[ 4 5 6 ]
[ 3 4 5 ]
print_grid(5)
[ 5 6 7 ]
[ 4 5 6 ]
[ 3 4 5 ]
[ 2 3 4 ]
[ 1 2 3 ]
print_grid(4)
[ 4 5 6 ]
[ 3 4 5 ]
[ 2 3 4 ]
[ 1 2 3 ]
[ 0 1 2 ]
Use this starter code:
Submit this program as grid_numbers.py
.
If you are having difficulty solving (or simply approaching) a problem, start with a more simple sub-problem.
For instance, begin Problem 1 by figuring out how to print 7 8 9
using a loop:
Next, figure out how to add the brackets [
and ]
Continue to build a solution to the full problem by incrementally solving sub-problems.
Write a program that defines a function called box
, which produces a box comprised of +
characters, of height size
and width twice size
.
For example, with size = 5
, the output would be:
++++++++++
+ +
+ +
+ +
++++++++++
With size = 8
, the output would be:
++++++++++++++++
+ +
+ +
+ +
+ +
+ +
+ +
++++++++++++++++
Use the following starter code, and turn in your program using this format.
Submit this program as box.py
.
Note: Pay careful attention to your output! Match the examples.
A program intends to print the following:
"From an essay a student was reading on the RER, between
Chatelet-les-Halles and Luxembourg, one sentence stood out:
"Truth is related to reality.""
- Annie Ernaux
"Other people's life stories are not a topic for debate.
One should hear them out, and reciprocate in the same coin." - Olga Tokarczuk
"I stumble on this phrase of George Sand's:
"Poor workers or sick people, you must always struggle against those who tell you:
'Work hard to live badly.'" " - Laurent Binet
Here is the draft program. It contains several bugs. Fix them.
print(""From an essay a student was reading on the RER,\n between Chatelet-les-Halles and Luxembourg, one setence stood out:\n\"Truth is related to reality."" - Annie Ernaux'')
print('"Other people's life stories are not a topic for debate.\n One should hear them out, and reciprocate in the same coin." - Olga Tokarczuk')
print("I stumble on this phrase of George Sand's: "Poor workers or sick people,\nyou must always struggle against those who tell you:\n 'Work hard to live badly.'" " - Laurent Binet")
Submit this program as quotations.py
.
Write a program similar to the program in Problem 4, that prints every ordinal number between 1st
and 101st
, each on a new line:
Your output will start:
1st
2nd
3rd
4th
5th
6th
and end:
97th
98th
99th
100th
101st
The final program should use only one loop.
Submit this program as moredinals.py
.
Write a function fizzbuzz
that takes as input an integer and prints:
'fizz'
if the integer is evenly divisible by 3'buzz'
if the integer is evenly divisible by 5Here is the draft program. Complete it.
def fizzbuzz(input_int)
print(input_int)
# these are tests, keep them to check if your code works
fizzbuzz(2)
fizzbuzz(3)
fizzbuzz(4)
fizzbuzz(5)
fizzbuzz(6)
fizzbuzz(7)
The output of the tests included in the starter code should be:
2
fizz
4
buzz
fizz
7
Your code should work for inputs between 1 and 14, inclusive. Submit this program as fizzbuzz_func.py
.