Lab 3
Lab 3
- Write a function named
right_justifythat takes a string namedsas a parameter and prints the string with enough leading spaces so that the last letter of the string is in column 70 of the display.>>> right_justify('monty') montyHint: Use string concatenation and repetition. Also, Python provides a built-in function called
lenthat returns the length of a string, so the value oflen('monty')is 5. - Write a function that draws a grid like the following:
+ - - - - + - - - - + | | | | | | | | | | | | + - - - - + - - - - + | | | | | | | | | | | | + - - - - + - - - - +Hint: to print more than one value on a line, you can print a comma-separated sequence of values:
print('+', '-')By default, print advances to the next line, but you can override that behavior and put a space at the end, like this:
print('+', end=' ') print('-')The output of these statements is ‘+ -‘ on the same line. The output from the next print statement would begin on the next line.
Note: This exercise should be done using only the statements and other features we have learned so far.
- Write a function that draws a similar grid with four rows and four columns.