#Quiz2

I had this quiz quite some time ago, it was about time I wrote about this. 

Well, first of all, what the quiz asks us to do is create a file and write down a function called “superpower”. It should accept two parameters and return the value of first parameter elevated to the power of the second parameter, for example, superpower(a, b) should return the value of a^b power. This was my answer :

————————————————————————–

Editor :

Screen Shot 2016-02-15 at 10.44.54 AM

Terminal :

Screen Shot 2016-02-15 at 10.45.09 AM

————————————————————————–

There. So the code works perfectly, maybe we could add some user-friendliness with some more strings. 

————————————————————————–

Editor :

Screen Shot 2016-02-15 at 10.55.06 AM

Terminal :

Screen Shot 2016-02-15 at 10.54.13 AM

————————————————————————–

Nice going.

The next part of the quiz is to write a function called stars that accepts one parameter and prints as many stars in the same line. For example, stars(3) should print “***”, and stars(9) should print “*********” . 

This was my answer :

————————————————————————–

Editor :

Screen Shot 2016-02-15 at 11.04.30 AM

Terminal :

Screen Shot 2016-02-15 at 11.05.27 AM

————————————————————————–

Done, right? The stars are printed in the same line because of the comma after the string. That should be enough. Not quite, the stars are printed, but the comma causes a space between each star. After thinking about this for a little, I figured we could append each star on a list and join them, but actually it’s easier to join them as it is, as a string. Talking about easier solutions, now that I think about it, multiplying the string would be way easier:

————————————————————————–

Editor :

Screen Shot 2016-02-15 at 3.04.49 PM 

Terminal :

Screen Shot 2016-02-15 at 3.06.06 PM

Screen Shot 2016-02-15 at 3.06.22 PM

————————————————————————–

Yes, it works. Well, there must be more ways of doing this but I don’t think the solution can get any easier, so… I’m leaving this up to here. 

This is my post for the #quiz2 on my Programming Fundamentals course.

CC BY-SA 4.0 #Quiz2 by esenombredeusua is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.