- Lists: creating, indexing, slicing, modifying
- List methods:
append(),insert(),remove(),pop(),sort(),reverse(),index(),count() - Built-in functions:
len(),min(),max(),sum() inoperator for listsforloop,range(),enumerate()whileloopbreakandcontinue- Nested loops
- Building and filtering lists with loops
Create a list of 5 favorite movies. Then:
- Print the first and last movie
- Add a new movie to the end
- Insert a movie at index 2
- Remove one movie by name
- Print the final list and its length
Ask the user to enter 5 numbers (one at a time using a for loop and input()).
Store them in a list, then print:
- The list of numbers
- The sum
- The average
- The largest and smallest number
Using a for loop and range(1, 21), separate numbers into two lists: evens and odds.
Print both lists.
Using a while loop, ask the user to enter a password.
- If the password is "python123", print "Access granted!" and stop.
- If wrong, print "Wrong password, try again."
- After 3 failed attempts, print "Account locked!" and stop.
(Hint: use a counter variable and
break)
Ask the user for a number. Using a for loop, print the multiplication table for that number from 1 to 10.
Example for number 4:
4 x 1 = 4
4 x 2 = 8
...
4 x 10 = 40
Ask the user to enter a sentence. Using a loop:
- Count the number of vowels (a, e, i, o, u)
- Count the number of consonants (letters that are not vowels)
- Print the results
(Hint: use
.lower()and checkif char.isalpha()before counting)
- Complete all tasks in
homework.py - Push your work to your GitHub repository
- Share the repository link with the instructor
python homework.py