# 전역변수 global : 함수 안과 밖에서 모두 사용가능한 변수
def hello():
print(name + '아 안녕!')
name = '주현'
hello()
print(name)
# 지역변수 local : 함수 안에서만 사용 가능한 변수
def add():
b = 3 #지역변수
print(a + b)
a = 5 #전역변수
add()
print(a)
c = 5
def C():
c = 3
print(c) # 3
C()
print(c) # 5
def D():
global d
d = 7
print(d)
D()
print(d)
print('----문제1----')
x = 10
def show():
print(x)
y = 5
print(y)
show()
print(x)
print('----내장 모듈----')
#모듈 : 프로그램에서 사용할 함수, 변수, 자료들을 미리 모아둔 것
import random
print(random.randint(1, 100)) #1~100 사이의 랜덤 정수 생성
print(random.random()) #0과 1 사이의 랜덤 실수 생성
print(random.choice([1, 2, 3, 4, 5])) #리스트의 랜덤 항목 선택
print(random.sample([1, 2, 3, 4, 5], 2))
print(dir(random))
import math
print(math.sqrt(4)) #제곱근
print(math.pi) #원주율
from math import sqrt #모듈의 특정 함수만 가져오기
print(sqrt(9))
import time as t #모듈의 별명 만들기
print(t.localtime())
t.sleep(5)
To embed this project on your website, copy the following code and paste it into your website's HTML: