Python Assignment #3

  1. For this first function we were asked to write a function that takes in a person’s name and prints out a greeting:

The following was the result:

2. For the next exercise we were asked to write a function that takes in a first name and a last name, and prints out a nicely formatted full name, in a sentence:

3. For the third exercise we were asked to write a function that takes in two numbers, and adds them together:

4. For this exercise the goal was to modify Addition Calculator so that your function returns the sum of the two numbers:

5. The next exercise asked us to consider the following expression, intended to print the square  root of 16: pow(16,(1/2))

6. The final exercised challenged us to define the variables x and y as lists of numbers, and z as a tuple:


Summary:

In tackling these tasks, I employed several key techniques and thought processes. I utilized function definition and iteration to streamline repetitive tasks, such as greeting multiple individuals or processing multiple sets of names and numbers. List manipulation techniques, including indexing and slicing, were used to access and modify specific elements and subarrays within lists. The concept of immutability was highlighted by attempting to modify a tuple, demonstrating the differences between mutable and immutable data structures in Python. Arithmetic operations and the use of the pow function illustrated basic mathematical computations and the importance of ensuring compatibility across different Python versions. And by structuring the code with modular functions, I ensured clarity and reusability, allowing for easy adjustments and extensions to the code.

Leave a comment