아래의 글을 참고하여 JUPYTER 노트북에서 바로 옮겨서 적용해봤다.
1. Guessing Game¶
In [4]:
import random # importing random module
how_many = 0
while(True):
guess_num = input() #assumed number
# ends when typed "exit" by using IF
if guess_num == "exit":
print("The Number of guesses you tried:%d."%how_many)
break
random_number = random.randint(1,10) # creating random number
how_many += 1
# comparing the input number with randomly created number
if random_number > int(guess_num):
print("too low")
elif random_number < int(guess_num):
print("too high")
else:
print("exactly right")
1
too low
2
too high
6
too low
1
too low
3
exactly right
2
too low
exit
The Number of guesses you tried:6.
2. Check Primality¶
In [9]:
def prime_check(num):
t = 2
while t * t <= num: #checking if there is any number that is divided into t ("if divided " means not a prime)
if num % t == 0:
return print("NOT A Prime")
t += 1
return print("Prime Number")
random_number = random.randint(1,10*3) #randomly creaing number
print("The Number is %d"%random_number)
prime_check(random_number)
The Number is 12
NOT A Prime
3. Remove Duplicates¶
In [11]:
lit = [1,2,3,4,1,2,3]
r_lit = list(set(lit)) #using SET characteristic
print(r_lit)
[1, 2, 3, 4]
4. Max of Three¶
In [33]:
def return_max(a,b,c):
if a > b and a>c: #checking a
return a
elif b >a and b >c:#checking b
return b
else: # if a,b not a max number, c must be max number
return c
a,b,c = map(int,input().split(" ")) # getting 3 number
ans = return_max(a,b,c)
print(ans)
2 2 100
100
In [30]:
print(a)
100
In [ ]:
'Data Science > 알고리즘 공부' 카테고리의 다른 글
[백준][파이썬] 1182 부분수열의 합 (0) | 2021.01.18 |
---|---|
[백준][파이썬] 6603 로또 (0) | 2021.01.15 |
[백준][파이썬] 14889 스타트와 링크 (0) | 2021.01.13 |
[백준][파이썬] 1339번: 단어수학 (0) | 2021.01.09 |
[백준][파이썬] 2529번 부등호 (0) | 2021.01.09 |
댓글