please find the attached question,
https://drive.google.com/file/d/16FXm713RhW_XZ-uWTuqVthMppHb4iAcE/view?usp=sharing
a)
Scopes determine in which part of the program we can work with a particular variable, and from which the variable is "hidden". It is extremely important to understand how to use only the values and variables that we need, and how the language interpreter behaves in this case. There are as many as 3 scopes in Python:
Local
Global
Non - local
1)The variables that were defined both inside and outside the function are visible from inside the function. Variables defined internally are local, externally global.
2)No variables defined inside the functions are visible from the outside.
3)From inside the function, you can change the value of variables that are defined in the global scope using the global specifier.
4)From inside the nested function, using the nonlocal specifier, you can change the values of variables that were defined in the external function, but are not in the global scope.
b)
def score_to_grade(score):
if(score < 0.6 and score > 0):
print("grade: F")
return
if(score >= 0.6 and score < 0.7):
print("grade: D")
return
if(score >= 0.7 and score < 0.8):
print("grade: C")
return
if(score >= 0.8 and score < 0.9):
print("grade: B")
return
if(score >= 0.9 and score <= 1):
print("grade: A")
return
print("please enter score between 0.0 and 1.0")
score = float(input("enter score between 0.0 and 1.0: "))
score_to_grade(score)
Comments
Leave a comment