Quiz01 – Defining and Testing

First quiz, and as I had no computer to work with, I answered it on paper. The first step was to create a python file named prog1.py that contains a function that has a cylinder’s radius and a height as parameters and outputs the cylinder’s volume. Now let’s test what I did:

———————————————————————-

Screen Shot 2016-02-09 at 8.59.09 AM

———————————————————————-

There’s the function, but that’s just the beginning, let’s test it, of course :

———————————————————————-

Editor : 

Screen Shot 2016-02-09 at 9.25.32 AM

Terminal : 

Screen Shot 2016-02-09 at 9.33.35 AM

———————————————————————-

To prove my answer as correct I  called my function with a and b as parameters, when a and b are inputs by the user, raw_input returns data as strings, that’s why I call float on it. Here I am using python 2.7.11, if you are using python 3 you’d have to change raw_input for input and add parentheses when calling print on volume: print(volume(a, b)).

Next is the second part. As expected, the new python file is named prog2.py, it should ask for two numbers and return their product, their integer division, and the remainder from their division. This is what I turned in : 

———————————————————————-

Editor : 

Screen Shot 2016-02-09 at 9.32.40 AM

Terminal : 

Screen Shot 2016-02-09 at 9.31.46 AM

———————————————————————-

This second part didn’t ask to use float numbers, but integers, thus int is called on the input. It wasn’t necessary to edit this any further to prove the answer correct, as it proves itself.

This is my post for the first quiz on my Programming Fundamentals course.

CC BY-SA 4.0 Quiz01 – Defining and Testing by esenombredeusua is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.