Set up CoLab
Ran first block of code
What is the output you get?
30
Exercise: Using the pre-declared variables, calculate the area of a circle, and assign it to a new variable named 'area'. Print 'area' to the console.
Looked at code for swapping variables.
Had to eliminate extra lines to make code run.
Wrote code to swap values
Copied code for function example
Exercise: Write a function that will round a number to 'n' digits. Test your function using a print statement. Make sure the print statement is outside of your function.
Copied code for built in function practice.
What do you see when you execute this code?
cat
10
-543
645365
656743
3
[-543, 1, 3, 4, 23, 31, 324, 435, 5435, 5665, 645365]
Exercise: Write a function that takes in two lists as arguments. Your function must first find the max of both lists. It must return the product ('*') of the maxes. Test your function by printing to the console.
Copied example code for booleans.
What is the output of the above code?
False
True False True
Using print statements, and built-in functions min(), max(), sum(), write some code that either evaluates to True or False.
Copied code for conditional program flow.
For the assigned values of variables a and b, what is the output?
20 is greater than 10
Exercise: Change values of a and b such that other two conditions are met.
Copied example code for logic in functions
What is the output of the above code?
jfkdla;s
abcfdsafdasg
None
Wrote the practice code recalling the cake method.
What is the following line implying?
true
Exercise: Write a function to determine if the absolute value of the minimum in a list is odd. If it is odd, print 'odd' to the console. Else, print 'even' to the console
Copied list code and ran it
Add the following lines one by one to the above code and add comments to explain what they mean?
print(list_of_lists[0])
print(list_of_lists[1])
print(list_of_lists[0][1])
print(list_of_lists[0][2])
print(list_of_lists[1][0])
Exercise: You are analyzing sports teams. Members of each team are stored in a list. The Coach is the first name in the list, the captain is the second name in the list, and other players are listed after that. These lists are stored in another list, which starts with the best team and proceeds through the list to the worst team last.
Final is between the two teams. Complete the function below to select the captain of the losing team and print to console.
Exercise: The next iteration of Mario Kart will feature an extra-infuriating new item, the Purple Shell. When used, it warps the last place racer into first place and the first place racer into the last place.
Complete the function below to implement the Purple Shell's effect. Pass the list 'standings' into your function and print the updated standings to the console. (Hint: Keep in mind the concept of temporary variables from a previous lesson)
Copied code for for and while loops.
Ran code.
Exercise: Your lucky number is 7. You really like 7. You even like numbers divisible by 7 (do I smell a modulus operator?). Write a function that counts the frequency of numbers divisible by 7 in a list, and print that frequency to the console.
Copied example code for dictionaries.
Edited code based on comments
Copied example code for external libraries
What is the output? (Of example 2)
Outputs a plot of the sin function of voltage over time with labels and values
Exercise. Google the functions used by the matplotlib and numpy libraries to get an understanding of the flow of the code. In the blank code space below, import the matplotlib and numpy libraries and make any plot of your own. Use the above examples and the documentation pages to help you.
That's all folks.