-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgramming Fundamentals
More file actions
59 lines (44 loc) · 1.29 KB
/
Programming Fundamentals
File metadata and controls
59 lines (44 loc) · 1.29 KB
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
#If, elif, else statements
if x>5 and x<7: #condition 1
print('x is 6')
elif x=5 #condition 2
print('x is 5')
else: #if no condition is tue
print('x is not 6')
#could also use an OR statement like if x<2 or x>4
#define a function
def function_name(parameters):
function_name(arguments) #execute code with a function
def greet(name: print('Hello', name)
greet('Sarah')
def add(a,b): return a + b # return is keyword used to send a value back from a function to its caller
add(3,5)
#Class definition
class ClassName: #add attributes and methods
class Person:
def _init_(self, name, age):
self.name = name
slef.age= age
#Object creation
object_name=ClassName(arguments)
person1 = Person('Sarah', 24)
#For Loop, exectues code for specifc amount of iterations
for num in range (1,10):
print(name)
#loop controls
for num in range(1,6):
if num== 3:
break #breaks loop prematurely
print(num)
for num in range(1,6)
if num == 3:
continue #skips current iteration and moves to next
print(num)
#While Loop, executes code until a speicfic condition is satisfies
count=0 while count<5
print(count) count+=1
#random things to know
x==y #checks if two values are equal
>= greater than or equal to
< less than
!= is not equal