-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython101.py
More file actions
211 lines (155 loc) · 4.7 KB
/
Copy pathpython101.py
File metadata and controls
211 lines (155 loc) · 4.7 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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/bin/python3
##################################################################################
## ##
## #Python3 ##
## #This is a little 101 Script for Python3 ##
## #2019 written by rwx777 ##
## ##
####################################################################################
#Print strings
print("Hek the police")
print ("Hek" + "something")
#Print new line
print("\n")
################################################################################
#Math
print("Math Time")
print(77 + 77) #add
print(50 - 50) #subtract
print(50 * 50) #multiply
print(50 / 50) #divide
print(50 ** 2) #exponents
print(50 % 6) #modulo
print(50 // 6) #number without leftovers
print("\n") #new line
################################################################################
#Variables & Methodes
print("Fun with varibales and methods:")
quote = "Hacking is fun if youre a Hacker"
print(len(quote)) #length of quote
print(quote.upper()) #makes quote uppercase
print(quote.lower()) #lowercase
print(quote.title()) #title makes everyfirst letteler captial
name = "Elliot"
age = 23 #int int(23)
abi = 3.2 #float float(3.2)
print(int(age))
print(int(23.8)) # does not round
print("My Name is " + name + " and I am " + str(age) + " years old.") #nice
print("\n") #new line
age += 1
print(age) #now is 24
birthday = 1
age += birthday
print(age) #now 25
################################################################################
#Functions
print("Now, some functions:")
def who_am_i():
name = "Elliot"
age = 23 #int int(23)
print("My Name is " + name + " and I am " + str(age) + " years old.") #nice
#variables delcared in function are only avidlble in function
who_am_i() #called function
#adding in parameters
def add_one_hundred(num):
print(num + 100)
#mini programm
add_one_hundred(50)
# will give us 150
#add in multiply parameters
def add(x,y):
print(x + y)
add(7,7) #adds 7+7 cus of the function we wrote
add(305,207) #adds 305 + 207
#using return
def multiply(x,y):
return x * y
print(multiply(7,7))
def square_root(x):
return x ** .5
print(square_root(64))
def new_line():
print("\n") #new line
new_line()
################################################################################
#boolean expressions (True or false)
print("Boolean expressions:")
bool1 = True
bool2 = 3*3 == 9
bool3 = False
bool4 = 3*3 != 9
print(bool1,bool2,bool3,bool4)
print(type(bool1))
bool5 = "True" #its a trap
print(type(bool5))
#################################################################################
#Relational und Boolean Operators
greater_than = 7 > 5
less_than = 5 < 7
greater_than_equal_to = 7 >= 7
less_than_equal_to = 7 <= 7
print(greater_than, less_than, greater_than_equal_to, less_than_equal_to)
test_and = (7>5) and (5>7) # True & True returns True
test_or = (7>5) or (5<7)
test_not = not True #is False
#check Truth Tables
new_line()
################################################################################
#Conditional Statments
print("Conditional Statments:")
def soda(money):
if money >= 2:
return "You have got a Soda!"
else:
return "NO Soda for you!"
print(soda(3))
print(soda(1))
def alcohol(age,money):
if(age >= 21) and (money >= 5):
return "Lets get Wasted!"
elif(age >= 21) and (money < 5):
return "You broke homi3!"
elif(age < 21) and (money >= 5):
return "Nice try, kid!"
else:
return "Youre too poor and too young"
print(alcohol(19,100))
print(alcohol(23,3))
print(alcohol(90,10))
new_line()
################################################################################
#Lists
print("LISTS have brackets:")
movies = ["Wall-E","The Great Gatsby","The Perks of being a Wallflower"]
print(movies[0]) #Lists start a 0 like arrays
print(movies[0:2]) #prints the first and the second item
print(movies[1:]) #up to but not encluding/ prints all movies from second to last
print(movies[:1]) #from to first to second
print(movies[-1]) #negative one gets last item from list
print(len(movies))
movies.append("JAWS")
print(movies)
movies.pop() #removes last item in List
print(movies)
person = ["Hannah","Clay","Zack"]
combined = zip(movies,person) #combines 2 lists
print(list(combined))
################################################################################
#Tuples
print("Tuples have paranthesis and cannot change") #static bzw imutable
grades = ("A", "B", "C", "D", "F")
print(grades[1])
new_line()
################################################################################
#Looping
print("For loops - start to finish of iterate:")
vegetables = ["cucumber","spinach","cabbage"]
for x in vegetables:
print(x)
print("While loops - Execute as long as True:")
i = 1
while i < 10:
print(i)
i += 1
#counts up to 10