diff --git a/COR1010/H8_1.py b/COR1010/H8_1.py new file mode 100644 index 0000000..7eede0c --- /dev/null +++ b/COR1010/H8_1.py @@ -0,0 +1,13 @@ +def isSymmetric(word): + for l, r in zip(word, reversed(word)): + if l != r: + return False + return True + +word = input("Enter a word : ") +result = isSymmetric(word) + +if result: + print(f"{word} is symmetric") +else: + print(f"{word} is asymmetric") diff --git a/COR1010/H8_2.py b/COR1010/H8_2.py new file mode 100644 index 0000000..3985ac9 --- /dev/null +++ b/COR1010/H8_2.py @@ -0,0 +1,17 @@ +import random + +def password(length): + lowercase = "abcdefghijklmnopqrstuvwxyz" + uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + numbers = "0123456789" + symbols = "!@#$%^&*" + all = lowercase + uppercase + numbers + symbols + + selected = random.choice(uppercase) + for i in range(length-1): + selected += random.choice(all) + + return selected + +length = int(input("Enter the length of password : ")) +print("Password is", password(length)) diff --git a/COR1010/H8_3.py b/COR1010/H8_3.py new file mode 100644 index 0000000..7247bf3 --- /dev/null +++ b/COR1010/H8_3.py @@ -0,0 +1,15 @@ +def countChars(s): + occurances = {} + for c in s: + c = c.lower() + occurances[c] = occurances.get(c, 0) + 1 + + return occurances + +input_str = input("Enter string : ") +occurances = countChars(input_str) + +print("=" * 30) + +for c, n in occurances.items(): + print("{} : {}번 사용되었습니다.".format(c, n)) diff --git a/COR1010/H9_1.py b/COR1010/H9_1.py new file mode 100644 index 0000000..c83f056 --- /dev/null +++ b/COR1010/H9_1.py @@ -0,0 +1,13 @@ +scores = {} + +with open("score.txt", "r") as f: + for line in f: + course, score = line.split() + course = int(course) + score = int(score) + + if course not in scores or scores[course] < score: + scores[course] = score + +for course, score in scores.items(): + print("{} 번 : {} 점".format(course, score)) diff --git a/COR1010/H9_2.py b/COR1010/H9_2.py new file mode 100644 index 0000000..375559d --- /dev/null +++ b/COR1010/H9_2.py @@ -0,0 +1,33 @@ +input_file = open("word_game.txt", "r") + +for line in input_file: + word = line.strip() + + guess_history = ["*"] * len(word) + + found_attempts = failed_attempts = 0 + while found_attampts < len(word): + guess_char = input("추측하는 문자 하나를 입력 {}----> ".format(guess_history)) + + if guess_char in guess_history: + print("{}은(는) 이미 찾은 문자입니다.".format(guess_char)) + elif word.find(guess_char) < 0: + print("{}은(는) 존재하지 않는 문자입니다.".format(guess_char)) + failed_attempts += 1 + else: + i = word.find(guess_char) + while i >= 0: + guess_history[i] = guess_char + found_attempts += 1 + i = word.find(guess_char, i + 1) + + print("찾는 단어는 {}입니다.".format(word)) + print("{}번 찾기 실패하였습니다.".format(failed_attempts)) + should_continue = input("단어 맞추기를 계속하시겠습니까? ") + + if should_continue.lower() == "n": + break + + print() + +input_file.close()