Full Name Exercise
While this assignment wasn't too difficult, it did take me a while to complete. The initial part of the assignment asked us to work with creating functions. To get a hang of the structure and syntax of functions in Python, I created a simple one initially and then added to it to create one that fit the parameters of the assignment. There was some trial and error involved but I figured it out.
 |
First Function |
 |
Greeting Function |
 |
Greeting Function |
 |
Greeting Function |
 |
For Loop
Addition & Return Calculator Exercise
The next part of the assignment asked us to create an addition calculator and use a return statement. This was fairly straightforward. The most difficult part for me was editing my function to print out the strings ("the total is") and correcting the spacing.
This part also asked us to evaluate the expression pow(16,(1/2)) which returns 4.0. A better way to write this expression would be pow(16, 0.5) which also returns 4.0. The power function can be used with both integers and decimals (floats) numbers. Changing the fraction to the decimal in the initial expression keeps the answer in the same format.
Variables, Lists, & Tuples
The last part of this assignment asked us to create two lists and one tuple and then locate variables within them.
It also asked us to evaluate two expressions. x[3]=8 returns [1,2,3,8,5]. It replaces the 4 with an 8. While z[3] =8 causes an error. This is because x is a list and z is a tuple. The values initially assigned in tuples are immutable and cannot be changed within expressions while this is possible within lists.
|
Comments
Post a Comment