๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐ŸŒ€ ํŒŒ์ด์ฌ Python

ํŒŒ์ด์ฌ - Import math , random

by Meteora_ 2021. 6. 28.
728x90
import math

print(math.sin(1))
print(math.cos(1))
print(math.tan(1))

print(math.floor(2.5))  # ๋‚ด๋ฆผ
print(math.ceil(2.5))   # ์˜ฌ๋ฆผ

# ์‚ฌ์‚ฌ์˜ค์ž… ์›์น™. ๋ฐ˜์˜ฌ๋ฆผํ•  ์ž๋ฆฌ์˜ ์ˆ˜๊ฐ€ 5์ด๋ฉด ๋ฐ˜์˜ฌ๋ฆผํ•  ๊ฒฝ์šฐ ์•ž์ž๋ฆฌ๊ฐ€ ์ง์ˆ˜๋ฉด ๋‚ด๋ฆผ, ํ™€์ˆ˜๋ฉด ์˜ฌ๋ฆผ
print(round(1.5))
print(round(2.5))

print(round(3.1415, 2))
print(round(31.415, -1))


import random

print(random.random())  # 0.0 <= r < 1.0

# uniform
print(random.uniform(10, 20))   # 10.0 ~ 19.99

print(random.randrange(10))     # 0 ~ 9

print(random.randrange(1, 5))   # 1 ~ 4

print(random.randint(1, 5))     # 1 ~ 5

print(random.choice([11, 33, 55, 7, 9]))

# shuffle
listA = [1, 2, 3, 4, 5]
random.shuffle(listA)
print(listA)

# sample
print(random.sample([1, 2, 3, 4, 5], k=5))

๋Œ“๊ธ€