71/ 72. Simple Exercise I

There are totally 7 problems in simple exercise I. Most of the exercises in this module are quite simple. I believe that you can do it pretty well. Good luck!

  1. Write a function called "printMany" that prints out integers 1, 2, 3, ..., 100.

<aside> 💡 1. function

def my_function(): function code here

  1. range

range(stop) range(start, stop) range(start, stop, step)

printMany();
# 1
# 2
# ...
# 100
  1. Write a function called "printEvery3" that prints out integers 1, 4, 7, 10, ..., 88.
printEvery3();
# 1
# 4
# ... 
# 88
  1. Write a function called "position" that returns a tuple of the first uppercase letter and its index location. If not found, returns -1.

<aside> 💡 #55. Return Keyword #49. Enumerate and Zip Function

  1. return()
  2. Enumerate Function

</aside>

position("abcd")  # returns -1
position("AbcD")  # returns ('A', 0)
position("abCD")  # returns ('C', 2)
  1. Write a function called "findSmallCount" that takes one list of integers and one integer as input, and returns an integer indicating how many elements in the list is smaller than the input integer.

<aside> 💡 1. Nested Loop

A nested loop is a loop inside a loop. The "inner loop" will be executed one time for each iteration of the "outer loop":

  1. counter

count() method can count the occurrences.

</aside>

findSmallCount([1, 2, 3], 2); # returns 1
findSmallCount([1, 2, 3, 4, 5], 0); # returns 0
findSmallCount([1, 2, 3, 4, 5], 100)  # returns 5
  1. Write a function called "findSmallerTotal" that takes one list of integers and one integer as input, and returns the sum of all elements in the list that are smaller than the input integer.