4일차: 무작위화 및 Python 목록

오늘의 교훈



4일차는 3일차에 비해 숨이 많이 쉬었던 것 같습니다. 과제와 동영상 강의가 조금 더 클릭되는 것 같습니다. 주요 테이크 아웃은 임의 모듈 및 목록의 사용이었습니다.

랜덤 모듈



random 모듈은 임의의 요소를 생성하는 데 도움이 되는 내장 모듈입니다. 그것은 꽤 직설적이었고 과제도 더 잘 설명되어 작업을 더 빨리 수행할 수 있었습니다.
그 예는 아래의 앞면 또는 뒷면 할당입니다.

#Remember to use the random module
#Hint: Remember to import the random module here at the top of the file. 🎲
import random
# 🚨 Don't change the code below 👇
test_seed = int(input("Create a seed number: "))
random.seed(test_seed)
 # 🚨 Don't change the code above 👆 It's only for testing your code.

#Write the rest of your code below this line 👇

random_int = random.randint(0, 1)

if random_int == 1:
    print("Heads")
else:
    print("Tails")


기울기



Python의 목록은 JS의 배열과 매우 유사합니다. 인덱싱, 인덱스 오류 및 중첩 목록을 검토했습니다.
명료하게 설명된 목록 과제도 마찬가지입니다.
아래 할당 예:

# 🚨 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 👆

#Write your code below this row 👇
horizontal = int(position[0])
vertical = int(position[1])


selected_row = (map[vertical - 1])
selected_row[horizontal - 1] = "X"

#Write your code above this row 👆

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


4일차 프로젝트 - 가위바위보



가위바위보 게임은 일단 논리를 이해하면 꽤 쉽게 끝낼 수 있다고 생각합니다. 기본적으로 0-2 범위의 사용자 입력으로 시작한 다음 임의 생성기를 사용하여 컴퓨터 입력을 얻습니다. 입력이 저장되고 정수로 변경된 후 if/elif 문을 여러 번 통과하여 값을 비교하고 누가 이겼는지 확인합니다. 내 코드는 아래에서 찾을 수 있습니다.

import random
rock = '''
    _______
---'   ____)
      (_____)
      (_____)
      (____)
---.__(___)
'''

paper = '''
    _______
---'   ____)____
          ______)
          _______)
         _______)
---.__________)
'''

scissors = '''
    _______
---'   ____)____
          ______)
       __________)
      (____)
---.__(___)
'''

# Write your code below this line 👇

user_choice = int(input(
    "What do you choose? Type 0 for Rock, 1 for Paper, 2 for Scissors:\n "))

computer_choice = random.randint(0, 2)
print(f"Computer chose {computer_choice}")

if user_choice == computer_choice:
    print("It's a tie!")
elif user_choice == 0 and computer_choice == 1:
    print("Computer wins!")
elif user_choice == 0 and computer_choice == 2:
    print("User wins!")
elif user_choice == 1 and computer_choice == 0:
    print("User wins!")
elif user_choice == 1 and computer_choice == 2:
    print("Computer wins!")
elif user_choice == 2 and computer_choice == 0:
    print("Computer wins!")
elif user_choice == 2 and computer_choice == 1:
    print("User wins!")
else:
    print("Invalid Input, loser")


EOD



힘든 하루를 보내고 오늘이 필요했던 것 같아요 3 😅. 나는 또한 내가 4일과 5일을 할 것이라고 말했다는 것을 알고 있지만 잠시 개 앉아 있어야 했습니다. 솔직히 말해서, 5일은 루프에 관한 것이고 그것은 항상 JS에서 저를 걸려 넘어지게 했습니다 롤에 대한 핸들이 없습니다. 그래서 나는 내일 그것에 대해 두 번 다시 말할 것입니다.

굿나잇 여러분 ✌🏾

내 진행 상황을 확인하고 싶거나 동료로 연결하고 싶다면 아래 내 소셜 링크를 확인하고 나를 팔로우하세요!



  • 💻 Github
  • 👾 Discord

  • 좋은 웹페이지 즐겨찾기