-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from RangHo/cor1010
[COR1010] Add homework 8 and 9 files
- Loading branch information
Showing
5 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |