For this activity, you will have the opportunity to write 3 different functions yourself, the function signatures and descriptions of which are below!
func1() : prints “Hello, world!”
Write a function with the signature "func1()" that prints "Hello, world!" and call it to see the output.
Note: This may "feel" like Module 1 again where we used print statements to write "Hello, World." The difference here is that we are now adding in a function to do this.
func2(input): prints the input with ‘!’ at the end
Write a function with the signature "func2(input)" that prints the input with an exclamation point at the end! Call it with any inputs to test it.
func3(n): prints “Calculating…” and returns n+n
Write a function with the signature "func3(n)" that takes in any input number n, prints the word "Calculating..." and then returns n+n. Outside of the function, you should assign the returned value of n+n to a variable and then print it.
Note: You can choose to assign the value of n by 1) hardcoding it by putting the value of "n" directly in the coding lines or 2) asking the user for input.
In this activity, you will write a function that calculates the total price of an item based on 3 parameters:
The item’s cost
The tax rate
The discount (in dollars)
Both the tax rate and discount should be optional parameters, with the default tax rate set to 0.05 and the default discount set to 0.0.
Print the output of the function when it is called with the following three combinations of arguments:
Cost = 100
Cost = 100, Tax Rate = 0.07
Cost = 100, Discount = 10
[Note: The discount comes after taxes are applied, not before].
Picture this: you work at an engineering firm that needs to randomly assign projects to interns. Given a list of interns and a list of teams with 5 projects each, randomly assign an intern to a team and project and output the result.
(It is okay if names or projects repeat; it does not need to be a perfect assignment generator 🙃)
The output should resemble the following (repeated for each intern):
Sally Smith: AI ChatBot Generation Team, Project 3
FizzBuzz is a simple game, often used in interview questions. The idea of the game is to receive a number as input, and do the following:
if the number is divisible by 3, we output "Fizz"
if the number is divisible by 5, we output "Buzz"
if the number is divisible by both 3 and 5, output "FizzBuzz".
Use your knowledge of if statements to solve this problem!
Note: To check if a number is divisible by another number, use the modulus operator (%). For example 25 % 5 == 0 evaluates to true, which means 25 is divisble by 5.
Given a list of temperatures for each day over a two week period, use a for loop to help you calculate the average temperature over the two week span! After calculating, print the average temperature.
Hint: you don't have to complete the final calculation inside the for loop!
To help you know whether or not your code is working, we will tell you that the average value rounds to 88.57.
You have been given two lists of components and their types, respectively.
ie. The first element in the components list is of the type of the first element in the types list.
Your job is to use for loops to print each element with its type. The output should resemble the following:
A company has recently learned that one of their manufacturers has recalled all products whose product codes’ digits sum to 34 or greater.
This company has asked you to write a program that will determine whether or not they have any recalled products in their inventory that they need to dispose of!
Given a list of product codes from their inventory, determine if any of these products have been recalled by the manufacturer.
If so, print the indices and product codes of all recalled products.
In your solution, make sure you create and use a function called is_recalled() that takes a product code as its parameter and returns True if the product is recalled and False otherwise.
Consider an elevator that has a weight limit of 6000 lbs.
Given an ordered list of weights of boxes (in lbs), your job is to figure out how many boxes can fit on the elevator without exceeding the weight capacity.
Assume that the boxes are added onto the elevator in the same order that they are listed in the provided list (from lightest to heaviest)
Go to your Colab notebook to complete this activity!
In this task, you will write a program that allows the user to input a password and checks to see if the password is correct.
If the user enters the wrong password, have them keep guessing until they input the right one.
If the user inputs the correct password, make sure they receive a confirmation message that they have been granted access to the system!
The program should continue to prompt the user to input the password again and again until the user inputs the correct password.
You can make the password anything that you want!
Now, we want to extend the code you wrote in your previous activity to only allow the user to guess the password 3 times.
You can just copy and paste your challenge 9 code and expand on it!
If the user inputs 3 incorrect passwords, they are denied access to the system and receive an appropriate error message.
If the user inputs the correct password, make sure they receive a confirmation message that they have been granted access to the system!
Before you submit, please make sure that your share settings are set so that anyone with the link is can comment on your notebook! Thank you!!