본문 바로가기
개발일지/Python

2022.01.17 유데미 파이썬 Day-3-2 완료

by 개발에정착하고싶다 2022. 1. 18.
320x100

첫번째
love_score 체크

이번 건은 내가 스스로 손도 대질 못했다.
따라서 모두 답안이다.
다만 답안의 흐름은 다음과 같다.

# 🚨 Don't change the code below 👇
print("Welcome to the Love Calculator!")
name1 = input("What is your name? \n")
name2 = input("What is their name? \n")
# 🚨 Don't change the code above 👆

#Write your code below this line 👇
conbined_string = name1+name2
lower_case_string = conbined_string.lower()

t = lower_case_string.count("t")
r = lower_case_string.count("r")
u = lower_case_string.count("u")
e = lower_case_string.count("e")

true = t+r+u+e

l = lower_case_string.count("l")
o = lower_case_string.count("o")
v = lower_case_string.count("v")
e = lower_case_string.count("e")

love = l+o+v+e
#위의 것들은 사실 숫자 (int)이다. 따라서 그 러브 스코어 게임을 하려면 각 글씨를 str로 해줘야한다.
love_score = str(true) +str(love)

print(love_score)

if (love_score <10) or (love_score >90):
  print(f"Your love score is {love_score}, you go together like coke and mentos.")
elif (love_score >= 40) and (love_score <=50):
  print(f"Your score is {love_score}, you are alright together.")
else:
  print(f"Your score is {love_score}")

문제1  
이게 실행이 되지 않았었다.
conbined_string = name1+name2
lower_case_string = conbined_string.lower()
부분에서
conbined 를 combined이라고 적었었기 때문이다.

문제2
근본적으로 마지막 if, elif, else문을 써줄 때 문제가 있었다.
기존의 love_score를 만들기 위해서
str형식으로 출력이 되었었는데
이를 if 문에 적용시키자면 불린이 아닌 이상
int로 전환해주어야 하기 때문이다.

때문에, 나는 이렇게 추가해주었다

print(love_score)
love_score = int(love_score)
원래는 단순히 한줄처리로하기 위해서 int(love_score)로 퉁치려고 했는데
안된단다 음.. 왜 안될까?
에러로는
TypeError: '<' not supported between instances of 'str' and 'int'
이렇게 나온다.
-> 모르겠다. 그냥 이건 받아들이는 영역이여야 하는것 같다.

아무튼 위의 int 처리를 위해서 강사님은 두가지 방법을 제시했다.
love_score = int(str(true) +str(love))
이렇게 통으로 int로 묶는것과
내가 했던 것처럼 변수처리를 해주는 것이다.


두번째

보물찾기

print('''
*******************************************************************************
          |                   |                  |                     |
 _________|________________.=""_;=.______________|_____________________|_______
|                   |  ,-"_,=""     `"=.|                  |
|___________________|__"=._o`"-._        `"=.______________|___________________
          |                `"=._o`"=._      _`"=._                     |
 _________|_____________________:=._o "=._."_.-="'"=.__________________|_______
|                   |    __.--" , ; `"=._o." ,-"""-._ ".   |
|___________________|_._"  ,. .` ` `` ,  `"-._"-._   ". '__|___________________
          |           |o`"=._` , "` `; .". ,  "-._"-._; ;              |
 _________|___________| ;`-.o`"=._; ." ` '`."\` . "-._ /_______________|_______
|                   | |o;    `"-.o`"=._``  '` " ,__.--o;   |
|___________________|_| ;     (#) `-.o `"=.`_.--"_o.-; ;___|___________________
____/______/______/___|o;._    "      `".o|o_.--"    ;o;____/______/______/____
/______/______/______/_"=._o--._        ; | ;        ; ;/______/______/______/_
____/______/______/______/__"=._o--._   ;o|o;     _._;o;____/______/______/____
/______/______/______/______/____"=._o._; | ;_.--"o.--"_/______/______/______/_
____/______/______/______/______/_____"=.o|o_.--""___/______/______/______/____
/______/______/______/______/______/______/______/______/______/______/_____ /
*******************************************************************************
''')
print("Welcome to Treasure Island.")
print("Your mission is to find the treasure.") 
choice1 = input('You\'re at a crossroad, where do you want to go? Type "left" or "right".').lower()

if choice1 == "left":
  choice2 = input('You\'ve come to a lake. There is an island in the middle of the lake. Type "wait" to wait for a boat. Type "swim" to swim across.').lower()
  if choice2 =="wait":
    choice3 = input("You arrive at the island unharmed. There is a house with 3 doors. One red, one yellow and one blue. Which colour do you choose?").lower()
    if choice3=="red":
      print("It's a room full of fire. Game Over.")
    elif choice3 =="yellow":
      print("You found the treasure! You Win!")
    elif choice3 == "blue":
      print("You enter a room of beasts. Game Over.")
    else:
      print("You choose a door that doesn't exist. Game Over.")
  else:
    print("You got attacked by an angry trout. Game Over.")
else:
  print("You fell into a hole. Game Over.")
#https://www.draw.io/?lightbox=1&highlight=0000ff&edit=_blank&layers=1&nav=1&title=Treasure%20Island%20Conditional.drawio#Uhttps%3A%2F%2Fdrive.google.com%2Fuc%3Fid%3D1oDe4ehjWZipYRsVfeAx2HyB7LCQ8_Fvi%26export%3Ddownload

#Write your code below this line 👇

이 부분은 확실히 내 스스로 만들 시도조차 해보려고 하질 않았다.
표를 보는데 익숙하지도 않았지만 익숙해져 보려고 시도해보지도 않았기 때문이다.
음.. 정확히는 그런 참고 표가 어디에 있는지 찾는데에 게을렀다.
좀 더 움직이도록 하자.

시사점1
그나저나 출력값은 모두 정상적으로 "작동은 된다."
그러나 출력 결과값이 나오는 창에서 뭔가 답안이 보인다고나 할까, 밀려서 보인다고나 할까.
처음보는 현상이 있어서 좀 당황스럽기도하다.
이걸 어떻게 물어봐야할지도 잘 모르겠고.

시사점2
중간중간에 ""사이에 ''가 들어가는 때에 \처리를 해주는 타이밍을 명확히 모르겠다.
아주 명확히 알겠는거는 예를 들어서 you're 과 같이 생략영어표현을 써줄때 어포스트로피라고 하나?
그것의 앞에 you\'re 이라는 식으로 써주는 것이다.

-------------------
스스로 너무 마음이 나태해져있다.
정말 너무 나태하다.
다시금 돌이켜서 내일은 성공하자!!!!!!!

300x250