Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python Programming Using Microsoft Visual Studio Please I need help writing a function named right_justify that takes a string named s as a parameter and

Python Programming Using Microsoft Visual Studio

Please I need help writing a function named right_justify that takes a string named s as 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')

monty

Hint: Use string concatenation and repetition. Also, Python provides a built-in function called len that returns the length of a string, so the value of len('monty') is 5.

Exercise 3.2. A function object is a value you can assign to a variable or pass as an argument. For example, do_twice is a function that takes a function object as an argument and calls it twice: def do_twice(f): f() f() Here's an example that uses do_twice to call a function named print_spam twice. def print_spam(): print('spam') do_twice(print_spam)

a. I have to write an example into a script and test it.

b. Modify do_twice so that it takes two arguments, a function object and a value, and calls the function twice, passing the value as an argument.

c. Copy the definition of print_twice from earlier in this chapter to your script.

d. Use the modified version of do_twice to call print_twice twice, passing 'spam' as an argument.

e. Define a new function called do_four that takes a function object and a value and calls the function four times, passing the value as a parameter. There should be only two statements in the body of this function, not four. Solution: http: // thinkpython2. com/ code/ do_ four. py .

Exercise 3.3. Note: This exercise should be done using only the statements and other features we have learned so far.

a. I have to write function that draws a grid like the one shown in your text on page 27.

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.

b. I have to write function that draws a similar grid with four rows and four columns. Solution: http: // thinkpython2. com/ code/ grid. py .

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems X Special Issue On Database And Expert Systems Applications Lncs 8220

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Stephen W. Liddle ,Klaus-Dieter Schewe ,Xiaofang Zhou

2013th Edition

3642412203, 978-3642412202

More Books

Students also viewed these Databases questions

Question

4. Similarity (representativeness).

Answered: 1 week ago

Question

10:16 AM Sun Jan 29 Answered: 1 week ago

Answered: 1 week ago