Skip to content

Latest commit

 

History

History
21 lines (19 loc) · 1.55 KB

File metadata and controls

21 lines (19 loc) · 1.55 KB

List Exercises 2

Write the code for these problems in a file called list_primes.py inside of the 01-list-primes directory of this repository.

  1. Create a list called primes and fill it with the first two prime numbers. Hint: a prime number is a positive number that is not divisible by anything except 1 and itself.
  2. Try to add the next prime number to the primes list by typing primes + 5. What happens?
  3. If you got an error, what does this error mean?
  4. Commit your code.
  5. Fix the error (if you got one), so that 5 will be added to the list.
  6. Use the statement primes.append(7,11) to add the next two prime numbers to the primes list. What happens?
  7. If you got an error, what does this error mean?
  8. Use the statement primes.append([7,11]) to add the next two prime numbers to the primes list. What happens? (Hint: you may have to print primes to see)
  9. Use the .pop() method on primes to remove this erroneous entry.
  10. Commit your code.
  11. Fix the above statement and the .append() method twice to properly add 7 and 11 to the primes list.
  12. Use the statement primes.extend(13,17) to add the next two prime numbers to the primes list. What happens?
  13. If you got an error, what does this error mean?
  14. Use the statement primes.extend(13,17) to add the next two prime numbers to the primes list. What happens?
  15. Fix the above statement to properly use the .extend() method to add 13 and 17 to the list.

*** A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.