## Welcome to HW2-3 task 1! ## There are 12 questions in this homework. Related questions are grouped together. ## Q2, Q3, Q6, Q8 all need you to answer in plain English. If you need more lines for your answer, ## just start a new line and put a "#" at the beginning. ## Q1, Q4, Q5, Q9, Q10, Q11, Q12 all need you to write programming statements. ## Q7 needs you to modify some programming statements, observe the result, and explain in English # Your name and student ID here: ############################## Question 1 and 2 ############################ # Q2: What do you think that this function does? # Your answer here: def countToN(n): for i in range(1,n+1): print(i) # We will ask the function to count to 10 countToN(10) # Q1: Write a programming statement that asks countToN() to count to 100 ############################## Question 3 and 4 ############################ # Q3: Just by looking at it, what do you think that this function does? # Your answer here: def printMyInfo(name, studentID): print("Hello, my name is", name, "and my student ID is", studentID) # Q4: Write a programming statement that will use the function printMyInfo() # to print out your name and studentID ############################## Question 5, 6 and 7 ############################ # Q6: What do you think that this function does? # What do the variables a, b, and c do? # Your answer here: def addTwoNumbers(a, b): c = a+b return c; # This programming statement calls addTwoNumbers() x = addTwoNumbers(55, 101); print("The sum of 55 and 101 is", x) # Q5: Write a programming statement that calls addTwoNumbers() to add 103 and 927 # Q7: Instead of "return c", change the last line of addTwoNumbers() to return a. # What is the result? Is this correct? ############################## Question 8 ############################ # Q8: In your own words, write down what a function does. Specifically, mention: # a. What do the things in parentheses (..) do? # b. What is the purpose of the return? # You may find the equivalent from math useful: https://www.mathsisfun.com/sets/function.html # Note: students from EE and EIE (and other engineering/construction depts) -- you MUST # answer this question IN YOUR OWN WORDS. Trust me, we can tell when you've just # been copying from your lecture notes in the other class. ############################## Question 9 and 10 ############################ # Q9: Complete the following function, which sums up a list of numbers def sumUpList(list1): sum = 0 # go through the variable list1, update sum on each turn return sum # Q10: Write programming statements to use sumUpList() to sum up the elements of a # list of numbers (you decide what the list should contain. ############################## Question 11 and 12 ############################ # Q11: Complete the following function, which checks if a given element is already # in a list. It returns True if the element already exists in the list; False if not. def existsInList(myList, element): found = False # go through myList, update the variable found if needed. return found # Q12: Given the following list and the word, call existsInList() to find out # whether the variables word1 and word2 exist in the list. Print out the answer thisList = ["Tiger", "tiger", "burning", "bright"] word1 = "Tiger" word2 = "TIGER"