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

2022.01.18 Day-4-1 유데미 파이썬 부트캠프 후기 (난이도 상)

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

와... Day 4의 중반부터는 진짜 어려웠다.

특히 거의 끝나갈 즈음의 프로젝트는 뭘 말하고자하는지, 무슨 목표로 하는지도

도무지 이해가 안갔다.

 

 

첫번째
모듈 이용하기

import random
import my_module

random_integer = random.randint(1,10)
print(random_integer)

print(my_module.pi)

random_float = random.random()
print(random_float*5)

love_score = random.randint(1,100)
print(love_score)

이것이 선생님이 알려주신 것이다.
뭐 하나 알아서 할 수가 없었다.

두번째

머리가 나오는지, 꼬리가 나오는지
랜덤한 게임을 만들어봐라고 하셨는데
아예 손도 못댔었다.

#Write your code below this line 👇
#Hint: Remember to import the random module first. 🎲


import random

random_side = random.randint(0,1)
if random_side == 1:
  print("Heads")
else:
  print("Tails")

이건 선생님이 알려주신 코드다.

import random

game = random.randint(0,1)

if game == 1:
  print("Heads")
else:
  print("Tails")
이건 내가 복습차원에서 안보고 다시 생각해보며 만들었던 코드다.
아직도 이런 간단한것이지만 참고가 필요하다. 여전히...

세번째

리스트설명을 해주셨다.
그 중에서도 split 기능이 추후 매우 유용할 것같은데
좀 답답하다.

list_of_state_of_america = "Arizona Phoenix,Arkansas Little Rock,California Sacramento,Colorado Denver,Connecticut Hartford,Delaware Dover"

op = list_of_state_of_america.split(",")
print(op)
이게 내가 선생님의 split 코드를 참고하며 만든 코드다.
그런데 보통 추후 쓰게될 데이터는 가공되어있지 않은데
띄어쓰기를 출력해보면 \처리가 되어있다.
split으로 각 단어가 ""로 갈려지긴 하는데 공백이 \처리 되지않고 깔끔하게 되는 방법이 분명
있을것이니 차후에 찾아보도록 하자.

names_string = input("Give me everybody's names, separated by a comma. ")
names = names_string.split(",")
이거는 기본적으로 넣어주신 코드인데
입력값을 1,2,3
이라고 넣으면
['1', '2', '3']
이라고 정리되어서 나온다.

이 부분에 관해서

import random
# Split string method
names_string = input("Give me everybody's names, separated by a comma. ")
names = names_string.split(", ")
# 🚨 Don't change the code above 👆

#Write your code below this line 👇

#Get the total number of items in list.
num_items = len(names)
#Generate random numbers between 0 and the last index.
random_choice = random.randint(0,num_items - 1)
person_who_will_pay = names[random_choice]

print(person_who_will_pay + "is going to buy the meal today!")

선생님것을 최대한 따라했다고는 했지만 뭔가 중간부터 따라했고 딴생각 하느라 집중력이 떨어졌었다.
이에대한 결과값이
"input 중 한명의 이름" is going to buy the meal today!
가 되어야 했을 건데
"input 모두의 이름" is going to buy the meal today!
이 되어버렸다.

그래서 다시 중간으로 돌아가서 해봤다.

import random
# Split string method
names_string = input("Give me everybody's names, separated by a comma. ")
names = names_string.split(", ")
# 🚨 Don't change the code above 👆

#Write your code below this line 👇

#Get the total number of items in list.
num_items = len(names)
#Generate random numbers between 0 and the last index.
random_choice = random.randint(0,num_items - 1)
print(random_choice)


이렇게 되어있는데

random은 맨 위에 임폴트 해왔고
num_items 에서 이름 길이를 정의해줬는데
왜 출력할때마다 0이 나오는가
한 8번쯤 해주니깐 1이 나오더라.
왜 랜덤이 0에 치중되어있을까.

import random
# Split string method
names_string = input("Give me everybody's names, separated by a comma. ")
names = names_string.split(", ")
# 🚨 Don't change the code above 👆

#Write your code below this line 👇

#Get the total number of items in list.
# num_items = len(names)
# #Generate random numbers between 0 and the last index.
# random_choice = random.randint(0,num_items-1)
# person_who_will_pay = names[random_choice]
person_who_will_pay = random.choice(names)
print(person_who_will_pay+" is going to buy for meal of today")

이렇게 따라하는건 분명히 완벽히 한것 같은데 뭐가 문제가 있어서
input한 이름 중 하나만 랜덤하게 나오는게 아니라
input한 이름 전부가 함께 출력되는걸까?


네번째

리스트가 약간만 좀 더 활용하려고 해도 응용이 참 난해하구나 .. 싶다..

fruits = ["Strawberries", "Nectarines", "Apples", "Grapes", "Peaches", "Cherries", "Pears"]
vegetables = ["Spinach", "Kale", "Tomatoes", "Celery", "Potatoes"]
 
dirty_dozen = [fruits, vegetables]
 
print(dirty_dozen[1][1])

이게 문제 코드인데. 일단 답은 맞췄다.
심지어 세부순서 검증도 했다.
그런데 마지막 줄에서의 리스트 2개중 첫번째가 fruits 이다가 갑자기 vegetables 로 전환이 된게 참 신기하다.
왜 그런걸까?


다섯번째

보물지도 퍼즐

# 🚨 Don't change the code below 👇
row1 = ["⬜️","⬜️","⬜️"]
row2 = ["⬜️","⬜️","⬜️"]
row3 = ["⬜️","⬜️","⬜️"]
map = [row1, row2, row3]
print(f"{row1}\n{row2}\n{row3}")
position = input("Where do you want to put the treasure? ")
# 🚨 Don't change the code above 👆

#23
#Write your code below this row 👇
horizonal = int(position[0]) #2
vertical = int(position[1]) #3

selected_row = map[vertical -1 ]
selected_row[horizonal -1] = "X"





#Write your code above this row 👆

# 🚨 Don't change the code below 👇
print(f"{row1}\n{row2}\n

이거는 코드를 뜯어보고 했는데도 정말 이해가 안가는 것이다.
무엇을 말하고자 하는지도 모르겠다.
박스의 특정 위치를 X로 바꿔준다는건 알겠는데
input하는것도 그렇고 뭔가 완성도에 대해서 이해를 못하겠다 근본적으로

 

Day에 하나씩 끝내고 싶은데 뭔가 나태해진다.

좀 나만의 나태해지지 않는 생산성 방법을 찾아야겠다.

책도 좀 읽고 싶다.

300x250