Академический Документы
Профессиональный Документы
Культура Документы
2 Date: 12/12/19
A variable num has been predefined as 5, alongside the following function definitions:
def func1():
num = 3
print(num)
def func2():
global num
double_num = num * 2
num = 6
print(double_num)
What value is printed out when func1() is called? 3
What is the value of num in the global scope after calling func1() and func2()? 6
3 Date: 12/12/19
Create a function named three_shouts(), which contains three parameters. This function returns a tuple of strings
concatenated with ‘!!!’. Call three_shouts(). The output should look like this:
4 Date: 12/12/19
Create function shout_echo that has two parameters: word and echo, which has a default value of 1. The function should
concatenate word with echo copies and 3 exclamation marks. Raise an error with raise if echo is less than 0 [ValueError (‘echo
must be greater than zero.’].
def shout_echo(word,echo=1):
if echo <0:
raise ValueError("echo must be greater than zero")
else:
echo_word = (word * echo) +'!!!'
return echo_word
shout_echo('Hey',-3)
Page 1 of 2
Name
BELMONTE, Bianca Lou F.
APPLIED DATA SCIENCE
2nd Qtr SY 2019-2020
Output
5 Date: 12/12/19
Create function shout_echo that has two parameters: word and echo, which has a default value of 1. The function should
concatenate word with echo copies and 3 exclamation marks. Raise an error with raise if echo is less than 0 [ValueError (‘echo
must be greater than zero.’].
def shout_echo(word,echo=1):
if echo <0:
raise ValueError("echo must be greater than zero")
else:
echo_word = (word * echo) +'!!!'
return echo_word
shout_echo(“Hey”,5)
Output
'HeyHeyHeyHeyHey!!!'
Page 2 of 2