-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
457 lines (308 loc) · 9.82 KB
/
Copy pathmain.py
File metadata and controls
457 lines (308 loc) · 9.82 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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
#for i in range(200000):
# print("Yo wassup")
# strings
#first_name = "Nika"
#last_name = "Idunno"
#email = "bro123@fake.com"
#print(first_name)
#print(last_name)
#print(f"your email is: {email}")
#-----
#integers
#age = 19
#print(f"your age is: {age}")
#quantity = 3
#print(f"you have {quantity} items in your cart")
#num_of_students = 30
#print(f"there are {num_of_students} students in the class")
#----
#floats
#price = 19.99
#gpa = 3.2
#print(f"the price of the item is: ${price}")
#print(f"your gpa is: {gpa}")
#distance = 5.5
#print(f"the distance to the destination is: {distance} kilometers")
#------
#booleans
#is_student = True
#print(f"are you a student?: {is_student}")
#if is_student:
# print("you are a student")
#else:
# print("you are not a student")
#for_sale = True
#if for_sale:
# print("the item is for sale")
#else:
# print("the item is not for sale")
#is_online = False
#if is_online:
# print("the player is online")
#else:
# print("the player is offline")
#------
#typecasting
# name = "Nika"
#age = 19
# gpa = 3.2
#is_student = True
#gpa = int(gpa)
#print(gpa)
#age = float(age)
#print(age)
#age = str(age)
#print(type(age))
#------
#input() a function that allows you to get user input from the console
#name = input("what is your name? ")
#print(f"hello {name}, nice to meet you!")
#print("happy birthday to you!")
#age = input("what is your age? ")
#age = int(age)
#age = age + 1
#print(f"you are {age} years old")
#------
#Exercise 1 rectangle area calc
#length = input("what is the length of the rectangle? ")
#width = input("what is the width of the rectangle? ")
#area = float(length) * float(width)
#print(f"the area of the rectangle is: {area}cm")
#------
#Exercise 2: Shopping cart program
#item = input("what item would you like to buy? ")
#price = input(f"what is the price of {item}?")
#quantity = input(f"how many {item}s would you like to buy? ")
#total = float(price) * float(quantity)
#print(f"the total cost of {quantity} {item}s is: ${total}")
#print(f"you have bought {quantity} x {item}/s")
#print (f"the total cost is: ${total}")
#-------
#madlibs game
#word game where you create a story
#by filling in blanks with different types of words (nouns, verbs, adjectives, etc.)
#adjective1 = input("enter an adjective: (description) ")
#noun1 = input("enter a noun: (person, place, or thing) ")
#adjective2 = input("enter another adjective: (description) ")
#verb1 = input("enter a verb ending with 'ing' (action) ")
#adjective3 = input("enter a third adjective: (description) ")
#print(f"today i went to {adjective1} zoo.")
#print(f"In an exhibit, i saw a {noun1}")
#print(f"{noun1} was {adjective2} and {verb1}")
#print(f"I was {adjective3}!")
#------
#friends = 10
#friends = friends + 1 same is down below
#friends = friends -2
#friends += 1
#friends = friends * 3
# friends /= 2
#friends = friends / 2
#friends = friends ** 2
#friends **= 2
#remainder = friends % 3
#print(remainder)
#x = 3.14
#y = -4
#z = 5
#result = round(x)
#result = abs(y) mteli an moduli
#result = pow(4,3) 4x4x4
#result = max(x,y,z)
#result = min(x,y,z)
#print(result)
#import math
#x = 9
#print(math.pi)
#print(math.e)
#result = math.sqrt()
#result = math.ceil(x)
#result = math.floor(x)
#print(result)
#import math
#radius = float(input('Enter the radius of a circle'))
#circumference = 2 * math.pi * radius
#print(f"The circumference is: {round(circumference,2)}cm")
#import math
#radius = float(input("Enter the radius of a circle:"))
#area = math.pi * pow(radius,2)
#print(f"The area of this circle is: {round(area, 2)}cm^2")
#import math
#a = float(input("Enter side A:"))
#b = float(input("Enter side B:"))
#c = math.sqrt(pow(a,2)+ pow(b,2))
#print(f"Side C = {c}")
# if = Do some code only IF some conditions is true
# Else do something else
#---- age example
#age = int(input("Enter your age: "))
#if age >= 100:
# print("You are too old to sign up!")
#elif age < 0:
# print("You haven't been born yet!?")
#elif age >= 18:
# print("You are now signed up!")
#else:
# print("You must be 18+ to sign up!")
#-----
#--- 2rd food example
#response = input("Would you like food?: (Y/N):")
#if response == "Y":
# print("Have some food!")
#else:
# print("No food for you!")
#----3rd example
#name = input("Enter your name:")
#if name == "":
# print("You didn't type in your name!")
#else:
# print(f"hello {name}")
#----4rd
#online = True
#if online:
# print("The user is online")
#else:
# print("The user is offline")
#Python calculator
#operator = input("Enter an operator (+ - * / ): ")
#num1 = float(input("Enter the first number: ")) # aq sachiroa float
#num2 = float(input("Enter the second number: "))
#print(num1 + num2) That's the first printing
#if operator == "+":
#result = num1 + num2
#print(round(result))
#elif operator == "-":
# result = num1 - num2
# print(round(result))
#elif operator == "*":
# result = num1 * num2
# print(round(result))
#elif operator == "/":
# result = num1 / num2
# print(round(result))
#else:
# print(f"{operator} is not a valid operator! ")
#Python weight converter program
#weight = float(input ("Enter your weight: "))
#unit = input ("kilograms or pounds? (K or L): ")
#if unit == "K":
# weight = weight * 2.205
# unit = "Lbs."
#elif unit == "L":
#weight = weight / 2.205
# unit = "kgs"
# print(f"Your weight is: {round(weight, 1)} {unit}")
#else:
#print(f"{unit} was not valid")
#-----
#Temperature conversion program
#unit = input("Is this temperature in Celsius or Fahrenheit? (C/F):")
#temp = float(input("Enter the temperature: "))
#if unit == "C":
# temp = round((9 * temp) / 5 + 32, 1)
# print(f"Current temperature in fahrenheit is: {temp}F")
#elif unit == "F":
# temp = round((temp - 32) * 5 / 9, 1)
# print(f"Current temperature in Celsius is: {temp}C")
#else:
#print(f"{unit} Is an invalid unit of measurement")
# ვქმნით მასივს (list)
# fruits = ["apple", "banana", "orange"]
# # ვბეჭდავთ მთელ მასივს
# print("ყველა ხილი:")
# print(fruits)
# # ვიღებთ ერთ ელემენტს ინდექსით
# print("პირველი ხილი არის:")
# print(fruits[0])
# # ვცვლით ელემენტს
# fruits[1] = "mango"
# print("banana შევცვალეთ mango-თი:")
# print(fruits)
# # ვამატებთ ახალ ელემენტს ბოლოში
# fruits.append("kiwi")
# print("დავამატეთ kiwi:")
# print(fruits)
# # ვშლით ელემენტს
# fruits.remove("orange")
# print("წავშალეთ orange:")
# print(fruits)
# # ყველა ელემენტზე გავლა
# print("ყველა ხილი ცალ-ცალკე:")
# for fruit in fruits:
# print(fruit)
# ვქმნით dictionary-ს
# student = {
# "name": "Nika",
# "age": 18,
# "grade": 95
# }
# # მთლიანი dictionary-ს დაბეჭდვა
# print(student)
# # ერთი მონაცემის მიღება
# print(student["name"])
# # მონაცემის შეცვლა
# student["age"] = 19
# # ახალი მონაცემის დამატება
# student["city"] = "Batumi"
# # მონაცემის წაშლა
# del student["grade"]
# # საბოლოო შედეგი
# print(student)
# # ყველა მონაცემის ნახვა
# for key, value in student.items():
# print(key, "=", value)
# sentence = input("write sentence: ")
# # deleting spaces
# sentence = sentence.replace(" ", "")
# # checking if the sentence is a palindrome
# if sentence == sentence[::-1]: # mteli teqsti igeba tavidan bolomde ar izgudeba saidan sad
# print("palindrome")
# else:
# print("not palindrome")
# firststr = input("write sentence: ")
# secondstr = input("what to find: ")
# replacestr = input("replace with: ")
# quantitystr = input("how many times to replace: ")
# if secondstr in firststr:
# firststr = firststr.replace(secondstr, replacestr, int(quantitystr))
# print("Result:", firststr)
# else:
# raise ValueError("Error: word not found in sentence")
# num = int(input("write number: "))
# reverse_num = 0 #საწყისი შედეგი
# while num > 0:
# digit = num % 10 #ბოლო ციფრის აღება 10-ზე გაყოფის ნაშთი ყოველთვის არის ბოლო ციფრი.
# reverse_num = reverse_num * 10 + digit #რიცხვს ვაცვლით “მარცხნივ”
# num = num // 10 # ბოლო ციფრის მოშორება
# print("Result:", reverse_num)
#------ bubble sort
# arr = [5, 3, 4, 1]
# n = len(arr)
# for i in range(n):
# for j in range(0, n - i - 1):
# if arr[j] > arr[j + 1]:
# arr[j], arr[j + 1] = arr[j + 1], arr[j]
# print("Sorted:", arr)
arr = input("Enter numbers separated by space: ").split()
for i in range(len(arr)):
arr[i] = int(arr[i])
n = len(arr)
for i in range(n):
for j in range(0, n - i - 1):
if arr[j] > arr[j + 1]:
arr[j], arr[j + 1] = arr[j + 1], arr[j]
def selection_sort(numbers, order):
for i in range(len(numbers)):
index = i
for j in range(i + 1, len(numbers)):
if order == "A":
if numbers[j] < numbers[index]:
index = j
elif order == "D":
if numbers[j] > numbers[index]:
index = j
numbers[i], numbers[index] = numbers[index], numbers[i]
return numbers
numbers = [15, 8, 23, 4, 19]
order = input("Ascending or Descending (A/D): ").upper()
print(selection_sort(numbers, order))