j
Course and Reading Material
One Dimensional Lists and Strings in Python
Formating floating point: b=float("{0:.2f}".format(a))
Tentative Future Plans
- Wed, Feb 1 - First Lab Assignment
- Friday, Jan 27 - Mini Quiz 1
- Friday, Feb 3 - Mini Quiz 2
- Friday, Feb 10 - Exam 1 - graded as Mini
Quiz
- Wed, Feb 15 - Exam 1
- Wed, March 1 - Exam 2
- Lab Assignments approx. every other week
Lecture Practice
The Community Center in City A offers a wide range of activities: various group exercise classes, gym, swimming pool, personal
training, etc.
For each activity, the Center publishes the number of calories could be burnt during 1 hour of exercise.
Write a program
that reads the number of activities a person participated during one week. The program creates a list of
activity names - list
of strings - user input. The program also randomly generates a list of integers -
number of hours spent on each activity per
week. The
program also randomly generates a list of integers - the number of calories that could be burnt
for 1 hour for each activity.
The program creates a new list - total_calories. Each entry in the list is the total number of calories burnt per week per
activity. The program also finds the activity with minimal number of calories burnt per week.
See example below:
activity_names=["Yoga", "Tai-Chi", "Swimming", "Running", "Walking"]
calories_per_hour=[154, 240, 400, 600, 340]
hours_per_week=[6, 3, 2, 2, 3]
total_calories=[924, 720, 800, 1200, 1020]
the activity with minimal calories burnt per week - Tai-Chi, with 720 calories burnt per week.
Make List and Make String Functions to use in your programs
Lecture Practice
Lecture/Lab Practice - Monday Feb 13
- Practice 1: Write a program that finds the name
of
the person who spends most of the hours on facebook in the
family.
The data will be stored in the followig way:
list of names - list of string
for each name you will have additional list of
7 integers
that holds number of hours that person was on
facebook for each day
of the week
The program finds a total number of hours for each
person per week, finds the maximal total, and
finds the person with maximal total
- Practice 2
Two Dimensional Lists
List Initialization
Option 1:
a = [[
0 for i in range(COL)] for j in range(ROW)]
The above line will create a list of ROW rows and COL columns and
assign value 0 to each element
Option 2
Generating Random 2d list of integers
Make List and Print 2d List in Table Form
Lecture Practice - Working with 2d list of integers
- Find sum of elements of 2d list
- Find average of elements of 2d list
- Find min/max element in 2d list
- Create a 1d list of all evens/odds from 2d list
- Search for specific number within the 2d list
Two-Dimensional Lists: Lecture and Lab Practice