Write the code for these problems in a file called list_primes.py
inside of the 01-list-primes
directory of this repository.
- 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. - Try to add the next prime number to the
primes
list by typingprimes + 5
. What happens? - If you got an error, what does this error mean?
- Commit your code.
- Fix the error (if you got one), so that 5 will be added to the list.
- Use the statement
primes.append(7,11)
to add the next two prime numbers to the primes list. What happens? - If you got an error, what does this error mean?
- 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) - Use the
.pop()
method on primes to remove this erroneous entry. - Commit your code.
- Fix the above statement and the
.append()
method twice to properly add 7 and 11 to the primes list. - Use the statement
primes.extend(13,17)
to add the next two prime numbers to the primes list. What happens? - If you got an error, what does this error mean?
- Use the statement
primes.extend(13,17)
to add the next two prime numbers to the primes list. What happens? - 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.