Py Warmup 2

  1. A list of the first 20 Fibonacci numbers. So $[1,1,2,3,5,\ldots]$.

  2. A list with the partial sums of the first 20 perfect fourth powers. So $[1^4, 1^4+2^4, 1^4+2^4+3^4, …]$.

  3. Write a function some_words that takes in a list of strings someWords and outputs a list of the strings in someWords that come after “grapefruit” in the dictionary and have at least 5 letters.

     someWords ["apple","mango","papaya","blueberry","juju"] == ["mango","papaya"]
    
  4. (Function: q4) Ask the person to type a number, use input(). Print 20 times that number.

  5. (Function: numpair) Given a string containing some integers separated by spaces, output a list of pairs (number, position), where position is the index of the number in the list - counting from zero.

     numpair "10 50 30 70" == [(10,0), (50,1), (30,2), (70,3)]
    
  6. (Function: largeRem) Given two integers, output the one with the largest remainder when divided by 1397.

     largeRem 2000 2800 == 2000
    
  7. (Function: myConcat) Given two lists, return the list made by joining all of the items from each, in order.

     myConcat [3,1,2] [50,60,70,80] == [3,1,2,50,60,70,80]
    
  8. (Function: lastPrint) Given a list of positive integers, modify the list by repeatedly removing the last item and printing it. Stop after you hit a four digit integer. Return the modified list.

  9. Make a deque with 10000 random integers in the range [-500,800]. Remove numbers from the start of the list stopping after you hit a number above 700. Add in 1000 more random numbers at the start.

  10. Create a list containing all of the Pythagorean triples $(a,b,c)$ with $a<100$ and $b<100$.

  11. Remove the duplicates from your list, so you end up with $a < b < c$. Sort them based on $a$ and then $b$.

Alternative

USACO bucket list problem: 2018 December Bronze 2.

Last modified August 28, 2023: Python introduction content days 1-4. (75c2bfd)