Quiz 4 Flashcards

1
Q

A definition of a function has what 2 parts

A
  1. The head
  2. The Block
    def fun_name():
    return statement
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why must you indent the statements in a block

A

so that the interpreter(Python) knows that statements are apart of the block

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are variables that receive pieces of data in a functions called?

A

Parameters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does the phrase “calling a function” mean?

A

execute the program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

When a function is executing, what happens when the end of the function’s black is reach?

A

Returns to where the function was called

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a variable’s scope?

A

a variable is only defined within the function that it is found

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
Write a statement that calls the function:
def message():
      print("I am glad it is tuesday")
A

message()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
Write a statement that calls the function:
def show_sum(num1,num2):
      result = num1 + num 2
      print (result)
A

show_sum(1,3)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
Write a statement that calls the function:
def area(width,length):
      return width*length
A

area(4,30)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
Write a statement that calls the function:
def area(width,length):
      return width*length
A

area(4,30)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Write a function called factorial that will take an integer as a parameter, and return the factorial of that number. You must use a for loop

A
def factorial(num):      
      total = 1
      for number in range (1,num+1):
             total = total*number
             return total
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
Write a statement that calls the function:
def show_double(number):
     result = number*2
     print(result)
A

show_double(5)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
Def calculate_circumference(num1,num2):
       circumference = 2*num1*num2
       return circumference
1) What is the name of the function?
2) What does the function do?
3) Given the function definition, what will the following statement display
print(calculate_circumference(3.1459,0.5)
A

1) calculate_circumference
2) Calculate the circumference of a 4 sided shape or circle
3) 3.1459

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Write a function named times_ten. The function should accept an argument and display the product of its argument multiplied times 10.

A
def times_ten (number):
      print(number*10)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
What will be displayed?
def main():
    x = 1
    y = 3.4
    print(x, y)
    change_us(x, y)
    print(x, y)
def change_us(a, b):
     a = 0
     b = 0
     print(a, b)
A

1, 3.4
0, 0
1, 3.4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Write a statement that generates a random number in the range of 1 through 100 and assigns it to a variable named rand.

A

import random
rand = random.randint (1,100)
print (rand)