Python Variable scopes
Fix the problem:
#####################################################################
# YI_MoreOnScopes3.py
# Mrs. Elia
# 12/18/14
# variables outside a definition and in other definitions
#
#####################################################################
# Definitions
#
#####################################################################
def increase():
num += 150
def decrease():
num -= 50
## main
num = 100
print(num)
increase()
print(num)
decrease()
print(num)
## desired output:
## 100
## 250
## 200
Hint:
num = 100 print(num) ...increase(...) print(num) ...decrease(...) print(num)
Fix this problem
#####################################################################
# YI_MoreOnScopes4.py
# Mrs. Elia
# 12/18/14
# variables outside a definition and in other definitions
#
#####################################################################
# Definitions
#
#####################################################################
def two_terms():
term1 = seed1 + seed2
term2 = seed2 + term1
return term1
return term2
## main
seed1 = 3
seed2 = 5
two_terms()
print(...)
## desired output:
## 8 13
Hint:
## main seed1 = 3 seed2 = 5 ...two_terms(...,...) print(...,...)
The output should be:
8 13
