15.6. ExercisesΒΆ

    1. Fill in the parameter list for g so that the invocations of g yield the return values specified

    1. Define a function called nums that has three parameters. The first parameter, an integer, should be required. A second parameter named mult_int should be optional with a default value of 5. The final parameter, switch, should also be optional with a default value of False. The function should multiply the two integers together, and if switch is True, should change the sign of the product before returning it.

    1. Write a function called together that takes three parameters, the first is a required parameter that is a number (integer or float), the second is a required parameter that is a string, and the third is an optional parameter whose default is ” β€œ. What is returned is the first parameter, concatenated with the second, using the third.

15.6.1. Contributed ExercisesΒΆ

Q-1: After completing the reading, what concepts are still unclear to you? If nothing is unclear, what did you find most interesting?

Write a function named add_wvu(). It should accept one parameter, an optional parameter named colleges designed to take a list. If an existing list is not provided for colleges when calling your function, your function should create a new list.

Your function must append an entry containing “WVU” to the colleges list, and return the updated list.

Be careful that if add_wvu() is called multiple times, any lists it generates are new and independent from other previously returned lists.

Create a lambda function that is designed to manipulate a dictionary, such as by returning the keys or values. Store the lambda function as lambda_func.

Create a function intadd that accepts two integers x and y. The first integer x should have a default value of 7 and the second integer y should have a default value of 3. The function should add the two integers and return this value.

    Q-1: Given the following sequence of stack operations, what is the top item on the stack when the sequence is complete?

    m = Stack()
    while not m.isEmpty():
  • 'x'
  • You may want to check out the docs for isEmpty
  • the stack is empty
  • There is an odd number of things on the stack but each time through the loop 2 things are popped.
  • an error will occur
  • Good Job.
  • 'z'
  • You may want to check out the docs for isEmpty

Below is a program that simulates the rolling of dice. Modify this code and use it to simulate the 100 rolls of 5, 10 sided dice. Store the average roll in a variable called solution rounded to the nearest integer.

You have attempted of activities on this page