Python In Class Exercises
Few guidelines for working in groups
- Finishing first doesn’t matter, what matters is working together
- If you know the answer, give others a chance to work it out for themselves
- If none of you know the answer, try reading the course materials and asking for help for the instructor
Exercise 1
Work together to figure how to use the data types, structures, and methods we discussed to solve these prompts:
- Get everyone’s first names in the group. Create a data structure to hold one name and then add each person’s name to the data structure. Whose name comes first? How would we change the order? How could we access an individual’s name? How could we access the first two names?
- Get everyone’s favorite number (or age). Calculate the average number for the group (hint: average is sum of all numbers divided by number of people in the group. You might check if Python has a built )
- Create a data structure to store each a set of movies (maybe your favorite techno-themed one? Think Blade Runner or Hackers). Update the structure to keep a count for each movie depending on how many people in the group have seen the movie. Make sure that you don’t keep any movie that only has a count of one.
Exercise 2
- Create a python script using the Command Line. Call the script
new_script.py
. - Recreate the steps from exercise 1
- BUT use the
input
method so that users can choose the initial values for both the strings and integers variables - AND use the
print
method to print out in the terminal each step of the exercise