Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Shout the Message

00:00 Last part of the challenge is to use string.shout(). The cool thing about functions is that you can actually pass a function call as an argument of another function.

00:12 So you can adjust a print() function call by not only passing in message, but passing in string.shout(), and then the message as a string for string.shout().

00:28 Save the file and jump over to string.py for a moment. There you can see that the shout() function returns string.upper().

00:38 So this function gives you back an uppercase string,

00:42 and in main.py, print() takes over and then outputs the message in uppercase. Let’s try it out again. Don’t forget to save. Run it in the interactive window.

00:56 And there you can see the uppercase message: THE AREA OF A 5-BY-8 RECTANGLE IS 40.

01:04 Again, to quickly check if everything works and is dynamic, adjust length to 9, save it, and run it again. And now it says THE AREA OF A 9-BY-8 RECTANGLE IS 72.

01:19 That’s correct. So that is nice. And you can change length back to 5 to stay with the requested solution of the challenge masters, whoever they are. And clean up the file.

01:33 Remove the comments, keep one or two blank lines after the import statements, and then you have the solution of the challenge, which in this case is a main.py file inside your project directory with the import statements from helpers import string and from helpers import calc.

01:55 You define the variables length = 5 and width = 8. And then you have a message which is an f-string where you format in the length and the width

02:04 and also the calc.area() function call with width and length. So that means your message is dynamic with the product of width and length.

02:15 And then in the end, you print the message that string.shout() returns back. Perfect. And that’s my solution to the challenge. Did you come up with something else?

02:26 Let me know in the comments below.

Become a Member to join the conversation.