-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAll_In_One2.py
More file actions
672 lines (481 loc) · 14.1 KB
/
All_In_One2.py
File metadata and controls
672 lines (481 loc) · 14.1 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
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
# scores = []
# for i in range(6):
# score = int(input(f"{i+1}번째 시험 점수 입력: "))
# scores.append(score)
# scores.remove(min(scores))
# total = sum(scores)
# if total >= 200:
# print("승진")
# else:
# print("보류")
# def positive_sum(numbers):
# if not numbers:
# return 0
# total = 0
# for n in numbers:
# if n > 0:
# total += n
# return total
# user_input = input()
# numbers = [int(x) for x in user_input.split()]
# result = positive_sum(numbers)
# print("합", r
# numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
# even_count = 0
# odd_count = 0
# for n in numbers:
# if n % 2 == 0:
# even_count += 1
# else:
# odd_count += 1
# print("짝수 개수:", even_count)
# print("홀수 개수:", odd_count)
# list1 = [1, 2, 3, 4, 5, 6]
# list2 = []
# sum_val = 0
# for num in list1:
# sum_val += num
# list2.append(sum_val)
# print(list2)
# def abc(data):
# max_count = 0
# result = None
# for x in data:
# if data.count(x) > max_count:
# max_count = data.count(x)
# result = x
# return result
# data = [1, 3, 2, 3, 4, 2, 2, 5, 3]
# print("rkqt:", abc(data))
# def abc(temp_list, k):
# count = 0
# for x in temp_list:
# if x > k:
# count += 1
# return count
# list1 = [10, 22, 10, 33, 10, 99, 55]
# k = 10
# print("결과:", abc(list1, k))
# sentence = input("문장을 입력하세요: ")
# words = sentence.split()
# word_count = len(words)
# total_length = 0
# for w in words:
# total_length += len(w)
# avg_length = total_length / word_count if word_count > 0 else 0
# print("단어 개수:", word_count)
# print("평균 길이:", avg_length)
# def select_p_words(words):
# new_words = []
# for w in words:
# if w.lower().startswith('p'):
# new_words.append(w)
# return new_words
# words = ['pear', 'apple', 'peach', 'grape', 'Pineapple']
# new_words = select_p_words(words)
# print("결과:", new_words)
# names = ['홍길동', '이만득', '김순미', '박서준', '최민지']
# phones = ['010-1234-5678', '010-9876-5432', '010-2345-6789', '010-5555-7777', '010-1111-2222']
# search_name = input("친구 이름을 입력하세요: ")
# if search_name in names:
# index = names.index(search_name)
# print(search_name, "의 전화번호:", phones[index])
# else:
# print(search_name, "은(는) 리스트에 없습니다.")
# name = list(map(str, input().split(',')))
# num = list(map(str, input().split(',')))
# def a(name):
# while(True):
# name_input = input()
# if name.find(name_input):
# print(num[name.index.name_input])
# result = []
# count = 1
# s = list(input())
# for i in range(1, len(s)):
# if s[i] == s[i - 1]:
# count += 1
# else :
# result.append(s[i-1])
# result.append(str(count))
# count = 1
# text = "aaabbccccd"
# result = []
# count = 1
# for i in range(1, len(text)):
# if text[i] == text[i-1]:
# count += 1
# else:
# result.append((text[i-1], count))
# count = 1
# result.append((text[-1], count))
# print(result)
# def get_min_max(numbers):
# return (min(numbers), max(numbers))
# nums = [3, 7, 1, 9, 5]
# result = get_min_max(nums)
# print(result)
# min_val, max_val = result
# print(min_val)
# print(max_val)
# location_data ={}
# location_data[(37.5665, 126.9780)] = "서울"
# location_data[(35.1796, 129.0756)] = "부산"
# print(location_data)
# a, b = (10, 20)
# print(a, b)
# x, y = 5, 7
# s, y = y, x
# print(x, y)
# students = [("홍길동", 90, 85, 95), ("김철수", 88, 79, 92), ("이영희", 92, 90, 85)]
# for name, math, eng, sci in students:
# avg = (math + eng + sci) / 3
# print(f"{name}의 평균 점수 : {avg:.2f}")
# numbers = [1, 2, 2, 3, 4, 4, 5]
# uni = set(numbers)
# print(uni)
# a = {1, 2, 3, 4}
# b = {3, 4, 5, 6}
# print("교집합 : ", a & b)
# print("합집합 : ", a | b)
# print("차집합 : ", a - b)
# print("대칭차집합 : ", a ^ b)
# f = {"apple", "banana"}
# f.add("orange")
# f.remove("banana")
# print(f)
# list1 = ["홍길동", "김철수", "이영희"]
# list2 = ["이영희", "박민수", "김철수"]
# common = set(list1) & set(list2)
# print("공통 학생", common)
# visited = set()
# for i in [1, 2, 3, 2, 4, 1, 5]:
# if i in visited:
# print(f"{i}는 이미 처리됨")
# else:
# print(f"{i} 처리 중...")
# visited.add(i)
# print(visited)
# en_kr = {'cat' : '고양이', 'dog' : '강아지', 'horse' : '말'}
# en_kr['cow'] = '암소'
# print(en_kr)
# en_kr = {'cat' : '고양이', 'dog' : '강아지', 'horse' : '말'}
# print('cow' in en_kr)
# en_kr = {'cat' : '고양이', 'dog' : '강아지', 'horse' : '말', 'cow' : '암소'}
# del en_kr['horse']
# print(en_kr)
# en_kr = {'cat' : '고양이', 'dog' : '강아지', 'horse' : '말', 'cow' : '암소'}
# print(en_kr.keys())
# print(en_kr.values())
# type(en_kr.keys())
# type(en_kr.values())
# print(en_kr.items())
# list(en_kr.items())
# c = {"korea" : "seoul", "USA" : "Washigton", "UK" : "London"}
# for i in c.items() :
# print(i, end = " ")
# fruits = ["apple", "banana", "grape"]
# for index, value in enumerate(fruits):
# print(index, value)
# import sys
# input = sys.stdin.readline
# print("공통 문자 : ", "".join(set(input()) & set(input())))
# text = input("입력 텍스트: ")
# words = text.split()
# unique_words = set(words)
# print("중복되지 않은 단어 개수:", len(unique_words))
# dict = {
# "one": "하나",
# "two": "둘",
# "three": "셋"
# }
# word = input()
# print(dict.get(word, "단어가 없습니다."))
# def main():
# address_book = {}
# while True:
# user = display_menu()
# if user == 1:
# name = input("이름 입력: ")
# phone = input("전화번호 입력: ")
# address_book[name] = phone
# print(f"{name} 연락처가 추가되었습니다.")
# elif user == 2:
# name = input("삭제할 이름: ")
# if name in address_book:
# del address_book[name]
# print(f"{name} 연락처가 삭제되었습니다.")
# else:
# print("없음")
# elif user == 3:
# name = input("검색할 이름: ")
# if name in address_book:
# print(f"{name}: {address_book[name]}")
# else:
# print("없음")
# elif user == 4:
# if address_book:
# for name in sorted(address_book):
# print(f"{name}: {address_book[name]}")
# else:
# print("등록된 연락처가 없습니다.")
# else:
# print("프로그램을 종료합니다.")
# break
# def display_menu():
# print("\n1. 연락처 추가")
# print("2. 연락처 삭제")
# print("3. 연락처 검색")
# print("4. 연락처 출력")
# print("5. 종료")
# select = int(input("메뉴항목을 선택하세요: "))
# return select
# main()
# students = {
# "Kim": [90, 85, 95],
# "Lee": [88, 79, 92],
# "Choi": [92, 90, 85]
# }
# for name, score_list in students.items():
# avg = sum(score_list) / len(score_list)
# print(name, avg)
# text_data = "Everybody should learn to program a computer because it teaches you how to think"
# texts = text_data.split()
# text_count = {}
# for i in texts:
# if i in text_count:
# text_count[i] += 1
# else :
# text_count[i] = 1
# for word, count in text_count.items():
# print(f"{word} : {count}")
# a = {1, 2, 3, 4}
# b = a
# a.add(5)
# c = list(a) + list(b)
# counter = 0
# for item in c :
# counter += 1
# print(counter
# def test_dic(d1, d2):
# d3 = {}
# for i in d1:
# if d1[i] in d2.keys():
# d3.update(i = d2[d1[i]])
# def test_dic(d1, d2):
# d3 = {}
# for i in d1:
# if d1[i] in d2:
# d1[i] = d2[d1[i]]
# return d3
# def init(data, value):
# ouputValue = 0
# for i in range(len(data)):
# if data[i] == value:
# ouputValue += 1
# return ouputValue
# tuple1 = (10, 8, 5, 2, 10, 15, 10, 8, 5, 8, 8, 2)
# user_input = int(input())
# outPut = init(tuple1, user_input)
# print(outPut)
# tuple1 = (10, 11, 12, 13, 14, 15)
# print(tuple1[::-1])
# lst1 = [15, 9, 10, 56, 23, 78, 5, 4, 9]
# lst2 = [9, 4, 5, 36, 47, 26, 10, 45, 87]
# lst3 = list(set(lst1) & set(lst2))
# print(lst3)
# list1 = [1, 2, 3, 4, 4, 5, 5, 5, 6]
# print(set(list1))
# def sum_all(data):
# a = sum(data)
# return a
# tuple1 = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
# a = sum_all(tuple1)
# print(a)
# def min_max(data):
# a = []
# a.append(min(data))
# a.append(max(data))
# a = tuple(a)
# return a
# list1 = [1.0, 4.0, -1.0, -6.0, 7.0, 3.0]
# list1.sort()
# outPut = min_max(list1)
# print(outPut)
# n = int(input("입력할 데이터의 개수를 입력하세요 : "))
# dict1 = {}
# for i in range(n):
# name = input('제품의 이름을 입력하세요 : ')
# price = input('제품의 가격을 입력하세요 : ')
# dict1[name] = price
# b = input("검색하고 싶은 가전제품의 이름을 입력하세요 : ")
# if b in dict1:
# print("가격 : ", dict1[b])
# else:
# print("등록되지 않은 가전제품 입니다.")
# id_password = {"이름1": "a", "이름2": "b", "이름3": "c", "이름4": "d", "이름5": "e"}
# user = input()
# password = input()
# if user in id_password:
# if id_password.get(user) == password:
# print("시스템에 로그인되었음")
# else :
# print("비밀번호 틀렸음")
# else :
# print("등록되지 않는 사용자")
# def hackJum(temp):
# hackJum = {"A+" : 4.5, 'A0' : 4.0, 'B+' : 3.5, 'B0' : 3.0, 'C+' : 2.5, 'C0' : 2.0, 'D+' : 1.5, 'D0' : 1.0, 'F' : 0.0}
# if temp in hackJum:
# return hackJum[temp]
# else :
# return "error"
# user = input()
# print(hackJum(user))
# def addDict(temp):
# return sum(temp.values())
# dict = {'a': 100, 'b' : 200, 'c' : 300}
# print(addDict(dict))
# def len_a_list(temp):
# result = {}
# for i in temp:
# result[i] = len(i)
# return result
# a_list = ["파이썬", "프로그래밍", "언어"]
# print(len_a_list(a_list))
# def init(temp):
# print(len(temp) - 1)
# print(sum(temp.values()) / len(temp))
# print(temp.items())
# dict = {}
# key = ''
# value = 0
# while(1):
# if key == 'END':
# a = init(dict)
# break
# key = input()
# value = int(input())
# dict[key] = value
# def full_day(short):
# a = input()
# if a in short:
# print(short[a])
# else :
# print("없습니다.")
# dict = {'일' : "일요일", "월" : "월요일", '화' : "화요일", '수' : "수요일", '목' : "목요일", '금' : "금요일", '토' : "토요일"}
# print(full_day(dict))
# dict = {"휘영" : "ryuwhi0@gmail.com", "휘영1" : "ryuwhi01@gmail.com", "휘영2" : "ryuwhi02@gmail.com", "휘영3" : "ryuwhi03@gmail.com", "휘영4" : "ryuwhi04@gmail.com"}
# a = input()
# if a == "추가":
# userId = input("userId를 입력하세요. ")
# userPassword = input("Email을 입력하세요. ")
# dict[userId] = userPassword
# elif a == "검색":
# userId = input("검색할 이름을 입력하세요. ")
# print(dict[userId])
# elif a == "삭제":
# userId = input("삭제할 이름을 입력하세요. ")
# del dict[userId]
# print(dict)
# def haha(lst):
# result = set()
# for i in lst:
# if lst.count(i) > 1:
# result.add(i)
# return result
# dups = ([1, 3, 2, 4, 3, 1, 1])
# print(haha(dups))
# scores = [95, 96, 100, 85, 95, 90, 95, 100, 95]
# count = {}
# for n in scores:
# count[n] = count.get(n, 0) + 1
# mode = max(count, key=count.get)
# print(mode)
# 리스트 실습 문제
# STUDENTS = 5
# list = []
# count = 0
# for i in range(5):
# a = int(input("성적을 입력하세요 : "))
# list.append(a)
# for i in range(5):
# if i > 80:
# count += 1
# print(max(list))
# print(min(list))
# print(count)
# print(sum(list) / STUDENTS)
# list = [3, 9, 4, 2, 15, 99]
# list.sort()
# print(list[1])
# scores = [10.0, 9.0, 8.3, 7.1, 3.0, 9.0]
# scores.sort()
# del scores[0]
# del scores[-1]
# print(scores)
# stack = []
# stack.append(10)
# stack.append(20)
# stack.append(30)
# print(stack)
# stack.pop()
# print(stack)
# menu = 0
# friends = ['홍길동', '박찬호', '손흥민']
# while menu != 9:
# print("----------------")
# menu = int(input("메뉴를 선택하세요 : "))
# if menu == 1:
# print(menu)
# elif menu == 2:
# name = input("친구 이름을 입력하세요 : ")
# menu.append(name)
# elif menu == 3:
# del_name = input("삭제하고 싶은 이름을 입력하세요 : ")
# if menu in name:
# del menu(name)
# else :
# print("이름이 없음")
# elif menu == 4:
# old_name = input("변경하고 싶은 친구 이름 입력")
# if menu in old_name:
# index = menu.index(old_name)
# new_name = input("새로운 이름을 입력하세요 : ")
# menu.insert(index, new_name)
# numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]
# print(numbers[-1::-2])
# del numbers[0]
# print(numbers)
# nums = []
# i = 1
# while(i < 100):
# if i % 2 == 0 and i % 3 == 0:
# nums.append(i)
# i += 1
# print(nums)
# list1 = [10, 20, 30, 40, 50]
# x = int(input('어디까지 입력할꺼야 썅칼 : '))
# a = 0
# for i in list1:
# a += i
# if i == x:
# break
# print(a)
# N = 100
# list = set()
# for a in range(1, N):
# for b in range(1, N):
# for c in range(1, N):
# if a ** 2 + b ** 2 == c ** 2:
# list.add(tuple(sorted((a, b, c))))
# for i in list:
# print(i)
# tuple = (10, 8, 5, 2, 10, 15, 10, 8, 5, 8, 8, 2)
# # count O
# print(tuple.count(8))
# # count X
# count = 0
# for i in tuple:
# if i == 8:
# count += 1
# print(count)