WorksheetsThird Day Quiz!
Total questions: 10
Worksheet time: 7mins
What's wrong with the syntax? (ignore the indentation)
def Function1();
print("hello world")
it doesn't take in any parameters
the semicolon should be replaced by colon
the function name starts with upper-case "F"
it doesn't return anything
A function is
Specific codes with a specific purpose(s) all together so they are maintainable and organized
A waste of time to use and it doesn't help your codes at all
Locate your codes in a single place so that it's easier to maintain
It's like a factory that may take into input (parameters) and process the input and give you a product (return)
How do I call the helloWorld function?
helloWorld
shout HELLO WORLD as loud as you can
helloWorld()
print("Hello World")
What's wrong with this code?
It doesn't return a*b
It's missing two required parameters
the syntax of the function is wrong
What will be the output and why?
False because the function is not equal to "Hello!"
False because "Hello!" is not equal to a
True because the voice_echo function will return "Hello!"
True because voice_echo function has been assigned to True by the return keyword
Which of the following statement is false?
Sometimes function doesn't take parameters, sometimes it doesn't return anything, it all depends on your use case
return is only used when there is at least one parameter
using a return without parameter(s) is possible
We should always use functions to group our codes with specific purpose(s)
Which of the hierarchical variable scope order is correct?
Local -> Enclosing -> Built-in -> Global
Built-in -> Global -> Enclosing -> Local
Enclosing -> Local -> Global -> Built-in
Local -> Enclosing -> Global -> Built-in
What will be printed out?
20
30
10
UnboundLocalError will be raised
Why do we use import?
To simplify our codes
So we can write thousands of line ourselves without using others' codes
So we can reuse a certain library that one has written in different programs
To save our time
which of the following is wrong?
import math as m
from math import * as a
from math import radians as rd
from math import sin
