Quiz Hack

questionNum = 3
correct = 0
questions = [
    "What is are correct names for a procedure? \n A) Method \n B) Function \n C) Both",
    "What is a procedure? \n A) Sequencing \n B) Selection \n C) Iteration \n D) All",
    "Use this for following question: \n def inchesToFeet(lengthInches): \n\t lengthFeet = lengthInches / 12 \n\t return lengthFeet \n\n What is the procedure name, the parameter, and what the procedure returns? \n A) feetToInches, lengthInches, lengthMeters \n B) inchesToFeet, lengthInches, lengthFeet \n C) inchesToFeet, lengthFeet, lengthInches \n D) lengthInches, inchesToFeet, lengthFeet"]
answers = ["c", "d", "b"]

def qna(question, answer):
    print("Question:", question)
    response = input()
    print("Answer:", response)
    
    if response.lower() == answer:
        print("Correct :) \n")
        global correct
        correct += 1
    else:
        print("Incorrect :( \n")
for x in range(questionNum):
    qna(questions[x], answers[x])
    
print("Score:", correct, "/ 3")
Question: What is are correct names for a procedure? 
 A) Method 
 B) Function 
 C) Both
Answer: c
Correct :) 

Question: What is a procedure? 
 A) Sequencing 
 B) Selection 
 C) Iteration 
 D) All
Answer: d
Correct :) 

Question: Use this for following question: 
 def inchesToFeet(lengthInches): 
	 lengthFeet = lengthInches / 12 
	 return lengthFeet 

 What is the procedure name, the parameter, and what the procedure returns? 
 A) feetToInches, lengthInches, lengthMeters 
 B) inchesToFeet, lengthInches, lengthFeet 
 C) inchesToFeet, lengthFeet, lengthInches 
 D) lengthInches, inchesToFeet, lengthFeet
Answer: b
Correct :) 

Score: 3 / 3

Hacks

Topic 3.12 (3.A):

  1. Define procedure and parameter in your own words
  • Procedure is part of a code that do a certain task. Parameter are variables that are used in the procedure.
  1. Paste a screenshot of completion of the quiz
  • Above
  1. Define Return Values and Output Parameters in your own words
  • Return values return procedure and output parameters gives you the parameter
  1. Code a procedure that finds the square root of any given number. (make sure to call and return the function)
import math

x = 10
def sqrt(x):
    return math.sqrt(x)

print(sqrt(x))
3.1622776601683795

Topic 3.13 (3.B):

  1. Explain, in your own words, why abstracting away your program logic into separate, modular functions is effective
  • Abstracted a program into separate functions is effective because it helps to reduce repeating code and it is easier to manage.
  1. Create a procedure that uses other sub-procedures (other functions) within it and explain why the abstraction was needed (conciseness, shared behavior, etc.)
  • The program find the sum of x and y.
x = 3
y = 5

def math(x, y):
    sum = x + y
    return sum

print(math(x, y))
8
  1. Add another layer of abstraction to the word counter program (HINT: create a function that can count the number of words starting with ANY character in a given string -- how can we leverage parameters for this?)

Topic 3.13 (3.C):

  1. Define procedure names and arguments in your own words.
  • Procedure names are the names given to produce an output. Arguments are the data that is input into the function.
  1. Code some procedures that use arguments and parameters with Javascript and HTML (make sure they are interactive on your hacks page, allowing the user to input numbers and click a button to produce an output)
    • Add two numbers
    • Subtract two numbers
    • Multiply two numbers
    • Divide two numbers
a=1 b=2