-
[random/inf loop] guessing game🐍 파이썬/파이썬 연습문제 2022. 7. 17. 07:26
문제 : Assign a random value to a variable and ask the user to guess the value. If the guess is lower than the chosen value, print ‘too low’, if it is greater, print ‘too high’. In case the number is correct, ‘correct’ and terminate the program.
take home: random library와 while True / break 구문을 활용한 infinite loop 작성하기
import random rnd = random.randint (0, 100) while True: guess = int input("guess between 0 to 100 : ") if guess < rnd: print("up!") elif guess > rnd: print("down!") else: pirnt("correct :D") break
'🐍 파이썬 > 파이썬 연습문제' 카테고리의 다른 글
[modulo/devisor] sum up digit (0) 2022.07.18 [file] copy the file (0) 2022.07.17 [input/string interpolation] 유저에게 인풋을 받아서 프린트하기 (0) 2022.07.17 [modulo/divisor] Vending machine change 거스름돈 문제 (0) 2022.07.17 [소개글] how to use 파이썬 연습문제 (0) 2022.07.15