Skip to content

Commit

Permalink
Merge pull request #16 from RangHo/cor1010
Browse files Browse the repository at this point in the history
[COR1010] Add homework 8 and 9 files
  • Loading branch information
RangHo authored Oct 30, 2023
2 parents 7b3cb9f + 5081ca4 commit a12a70d
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 0 deletions.
13 changes: 13 additions & 0 deletions COR1010/H8_1.py
Original file line number Diff line number Diff line change
@@ -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")
17 changes: 17 additions & 0 deletions COR1010/H8_2.py
Original file line number Diff line number Diff line change
@@ -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))
15 changes: 15 additions & 0 deletions COR1010/H8_3.py
Original file line number Diff line number Diff line change
@@ -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))
13 changes: 13 additions & 0 deletions COR1010/H9_1.py
Original file line number Diff line number Diff line change
@@ -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))
33 changes: 33 additions & 0 deletions COR1010/H9_2.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit a12a70d

Please sign in to comment.