-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBasics-FunctionsAndOperators.py
64 lines (52 loc) · 1.13 KB
/
Basics-FunctionsAndOperators.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
# Comment
'''
Multi
Line
Comments
'''
#Variables
helloWorld = "Hello World"
exampleVar = print("whoa")
x,y = (3,5)
#Print formatting and conversions
print("===STRINGS===")
print("Hello World")
print('Hello World with single-quotes')
print("%s %s %s"%("python","is","fun"))
print("%s with variable" %(helloWorld))
print('we\'re escaping single quotes because we\'re using single quotes for text And print')
print('Hi','there with a comma')
print('Hi', str(5),'with comma and string conversion')
#Math
print("===MATH===")
print(1+3)
print(3-1)
print(4*4)
print(5/2)
print(4**4)
print(x)
print(y)
print(x+y)
#Loops
print("===LOOPS===")
condition = 1
while condition < 5:
print(condition)
condition += 1
exampleList = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048]
#indentation is important (and mandatory!)
for eachNumber in exampleList:
print(eachNumber)
for x in range(1,4):
print(x)
#Functions (note the indentation)
def example():
print('basic function')
z = 3+9
print(z)
example()
def simple_addition(num1,num2):
answer = num1+num2
print('num1 is', num1)
print('answer is', answer)
simple_addition(10,42)