Notice
Recent Posts
Recent Comments
Link
«   2024/09   »
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
Tags
more
Archives
Today
Total
관리 메뉴

꼬물꼬물 개발자

while 본문

Python

while

한고운 2024. 8. 30. 01:01
# Python Standard Library 사용법
import random
#from random import randint

# if 함수
pc_choice = random.randint(1, 50)
user_choice = int(input("Choose number."))

if user_choice == pc_choice:
  print("You won!")
elif user_choice > pc_choice:
  print("Lower! Computer chose", pc_choice)
elif user_choice < pc_choice:
  print("Higher! Computer chose", pc_choice)
 

실행결과


# while 함수
distance = 0

while distance < 20:
  print(f"I'm running {distance} km")
  distance = distance + 1

실행결과


# if함수 -> while 함수
print("Welcome to Python Casino.")
pc_choice = random.randint(1, 100)

playing = True

while playing:
  user_choice = int(input("Choose number.(1-100)"))
  if user_choice == pc_choice:
    print("You won!")
    playing = False
  elif user_choice > pc_choice:
    print("Lower!")
  elif user_choice < pc_choice:
    print("Higher!")

실행결과

 

'Python' 카테고리의 다른 글

list, tuples, dictionary  (0) 2024.08.31
input, and, or  (0) 2024.08.29
if, else, elif  (0) 2024.08.23
Return  (0) 2024.08.22
Functions  (0) 2024.08.22