티스토리 뷰
import random
rock = '''
_______
---' ____)
(_____)
(_____)
(____)
---.__(___)
'''
paper = '''
_______
---' ____)____
______)
_______)
_______)
---.__________)
'''
scissors = '''
_______
---' ____)____
______)
__________)
(____)
---.__(___)
'''
#Write your code below this line 👇
game_images =[rock, paper, scissors]
user_choice = int(input("What do you choose? Type 0 for Rock , 1 for Paper or 2 for Scissors.\n"))
if user_choice >=3 or user_choice < 0:
print("you typed an invalid number, you lose!")
else:
print("You choice :\n")
print(game_images[user_choice])
computer_choice = random.randint(0,2)
print("computer chose :\n")
print(game_images[computer_choice])
if user_choice == 0 and computer_choice == 2:
print("You win!")
elif computer_choice == 0 and user_choice == 2:
print("You lose")
elif computer_choice > user_choice:
print("You lose!")
elif computer_choice == user_choice:
print("It's a draw")
Day 4, 랜덤 함수 , 리스트 , 배열
Python 부트 캠프 : 100개 프로젝트로 Python 공부!
# # random module
# # list
# a = 3
# # b = 'Hello'
# # print(a+1)
# # print(b)
# # items = ["item1", "item2","item3"]
# # print(items[0])
# # # count(items)
# # print(type(items))
# # print(len(items))
# # Split String method , rulet game (random,random.choice)
# import random
# name_string = input("Give me everybody's name, seperated by a comm ")
# names = name_string.split(",")
# print(names)
# names_len = len(names)
# print(names_len)
# random_names = random.randint(0,names_len - 1)
# print(random_names)
# choice = names[random_names]
# print(choice)
# print(random.choice(names))
# 가위 바위 보 게임 만들기
import random
rock = '''
_______
---' ____)
(_____)
(_____)
(____)
---.__(___)
'''
paper = '''
_______
---' ____)____
______)
_______)
_______)
---.__________)
'''
scissors = '''
_______
---' ____)____
______)
__________)
(____)
---.__(___)
'''
#Write your code below this line 👇
ran_user = random.randint(0,2)
ran_com = random.randint(0,2)
if ran_user == 0:
user = 0
print("user !!! " , rock)
elif ran_user == 1:
user = 1
# user1 = paper
print("user !!! " , paper)
else:
user = 2
# user2 = scissors
print("user !!! " , scissors)
if ran_com == 0:
com = 0
# com0 = rock
print("com !!! " , rock)
elif ran_com == 1:
com = 1
# com1 = paper
print("com !!! " , paper)
else:
com = 2
# com2 = scissors
print("com !!! " , scissors)
if user == com:
print
print("same!!! ")
if user == 0 and com == 1:
print(rock)
print(paper)
print("com wIN")
if user == 1 and com == 0:
print(paper)
print(rock)
print("com win")
if user == 1 and com == 2:
print(paper)
print(scissors)
print("com win")
else:
print(paper)
print(scissors)
print("user win")
까지 하다가 ㅡㅡ;;;;
몇일 놀다가 다시 쓴당(2022.08.16)
import random
rock = '''
_______
---' ____)
(_____)
(_____)
(____)
---.__(___)
'''
paper = '''
_______
---' ____)____
______)
_______)
_______)
---.__________)
'''
scissors = '''
_______
---' ____)____
______)
__________)
(____)
---.__(___)
'''
#Write your code below this line 👇
game_images =[rock, paper, scissors]
user_choice = int(input("What do you choose? Type 0 for Rock , 1 for Paper or 2 for Scissors.\n"))
if user_choice >=3 or user_choice < 0:
print("you typed an invalid number, you lose!")
else:
print("You choice :\n")
print(game_images[user_choice])
computer_choice = random.randint(0,2)
print("computer chose :\n")
print(game_images[computer_choice])
if user_choice == 0 and computer_choice == 2:
print("You win!")
elif computer_choice == 0 and user_choice == 2:
print("You lose")
elif computer_choice > user_choice:
print("You lose!")
elif computer_choice == user_choice:
print("It's a draw")
확실히 간결 해졌다... 단순한 산수 문제 일수 있는데 리스트 를 사용 하고 elif 를 통해 반복비교 했다.
난 역시 코딩 경험이 훨씬 더 많이 필요함을 느낀다.
'Programming > Python' 카테고리의 다른 글
파이썬 기초 공부 - Hangman (행맨) (0) | 2022.12.21 |
---|---|
Day 5. For , List , Random(Mathod/choice,shuffle) (0) | 2022.08.29 |
Day 3 . if / else (0) | 2022.08.05 |
Day 2 . Data type , f -string , Round (0) | 2022.08.02 |
Day 1. 변수 와 문자 입력 받기(print , input) (0) | 2022.08.01 |
- Total
- Today
- Yesterday
- 리눅스 환경변수 지정
- 리눅스 쉘 스크립트
- 파이썬실습
- 쉘 스크립트 기초
- Rcity CTF
- 리눅스
- 맨탈훈련
- rhcsa8 기출문제
- Rcity1번
- rhcsa8
- CTF
- Rcity
- grootsecuriry
- rhcsa8 시험문제
- 7-zip
- Rcityboan.com
- RCity operation 1
- rhcsa8 덤프
- 라쿤시티
- grootboan
- 주소DB만들기
- rhcsa8덤프
- gzip
- 파이썬기초
- Rcity 9번
- 리눅스 명령어
- 리눅스본딩
- Grootsecurity
- podman
- PODman기초
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |