티스토리 뷰
# data 구조
data = [
{
'name': 'Instagram',
'follower_count': 346,
'description': 'Social media platform',
'country': 'United States'
},
{
'name': 'Cristiano Ronaldo',
'follower_count': 215,
'description': 'Footballer',
'country': 'Portugal'
},
...
# 중첩 데이터의 key를 호출했으면
a=random.choice(data)
b=random.choice(data)
# 각 values는
a["name"]
a["follower_count"]
a["description"]
#형태로 호출할 수 있고
data[a]["name"]
#형태로도 호출할 수 있음
----------------------------------------------------------------------------
from art import logo, vs
from game_data import data
import random
import os
correct = False
user_score=0
a=0
def clean():
if os.name in ('nt', 'dos'): # If Machine is running on Windows, use cls
os.system('cls')
else:
os.system('clear')
clean()
print(logo)
def go_on(data, correct, a, user_score):
if correct == False:
a=random.choice(data)
b=random.choice(data)
if a == b :
b=random.choice(data)
else:
b=random.choice(data)
if a == b :
b=random.choice(data)
# print(f"a_count= {data[a]['follower_count']} , b_count= {data[b]['follower_count']}") #just for check
print(f"a_count= {a['follower_count']} , b_count= {b['follower_count']}")
# print(f"Compare A: {data[a]['name']}, a {data[a]['description']}, from {data[a]['country']}. ")
print(f"Compare A: {a['name']}, a {a['description']}, from {a['country']}. ")
print(vs)
# print(f"Compare B: {data[b]['name']}, a {data[b]['description']}, from {data[b]['country']}. ")
print(f"Compare B: {b['name']}, a {b['description']}, from {b['country']}. ")
# if data[a]['follower_count'] >= data[b]['follower_count']:
if a['follower_count'] >= b['follower_count']:
correct_answer = "a"
else :
correct_answer = "b"
print(f"correct answer = {correct_answer}") #just for check
user_answer = input("Who has more followers? Type 'A' or 'B': ").lower()
a=b
if correct_answer == user_answer:
correct = True
user_score+=1
clean()
print(logo)
print(f"You're right: Current score: {user_score}")
go_on(data, correct, a, user_score)
else:
clean()
print(logo)
print(f"Sorry, that's wrong. Final score: {user_score}")
go_on(data, correct, a, user_score)
'Test > Python(20220101~)' 카테고리의 다른 글
Days15_Coffee Machine (0) | 2022.01.30 |
---|---|
Days15 부터는 중급이래... 후덜.. (0) | 2022.01.22 |
Day13_How to Debugging (0) | 2022.01.18 |
Days12_Guess Number (0) | 2022.01.16 |
Days11_Black Jack, 21 (without comment) (0) | 2022.01.16 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- dezoomify
- virt-sysprep
- powershell
- 변수화
- 부동없이
- exadata
- powercli
- insert
- oracle
- EXA
- vmware
- 배열
- 중복제거
- dp-1
- set()
- 대소문자
- fromkeys
- 3par
- cloud-init
- LIST
- 읽어오기
- storage
- Join
- 정렬
- dp-2
- 차집합
- sysprep
- artandculture
- vmware.powercli
- 스토리지
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
31 |
글 보관함