-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.py
87 lines (72 loc) · 1.37 KB
/
script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# a = 1
# def add1(b) :
# return a+b
# c = add1(10)
# def f(*x):
# return sum(x)
def add(a) :
"""
This function adds two numbers
"""
b = a + 1
print(a, "If you add one you get = ", b)
return b
add(1)
def multi(a, b) :
"""
Multiply two numbers
"""
c = a*b
return(c)
print('This is not printed')
result = multi(12,2)
print("When multiplying", 12 ,"and", 2 ,"you get the =",result,"as the result.")
def square(a):
# Local variable
b = 1
c = a * a + b
print(a, "if you sqaure", 6 ,"+ 1 you get = ",c)
return(c)
square(6)
x = 3
y = square(x)
print(y)
def square(a):
# local varaibles
# varaibles that are defined inside a function
b = 1
c = a*a*+b
print(a,"if you sqaure +1",c)
#Global variables
# variables that are defined outside a function
x = 3
z = square(x)
print(z)
def f():
print("inside the function",s)
#Global variable
s = "I love studying"
f()
print("Outside function",s)
def f():
s = "Me too!"
print(s)
#Global variables
s = "I love studying"
f()
print(s)
# This function modifies the global variable 's'
def f():
global s
s += ' DANIEL'
print(s)
s = "Python is the best"
print(s)
# Global Scope
s = "Python is great!"
f()
print(s)
#define a string that concantenates two strings
def con(a,b):
return (a+b)
print(con("Hello","World"))