8>>1
8<<1
2&4 #and
2|4 #or
8^2 #ex or
~0
score = 1
while score != 0:
score=int(input("점수입력 : "))
if score>=90:
print("A")
elif score>=80:
print("B")
elif score>=70:
print("C")
elif score>=60:
print("D")
else:
print("F")
print("학점입니다.^^\n")
print("프로그램을 종료합니다")
score = 1
while True :
score=int(input("점수입력 : "))
if score == 0 :
break
if score>=90 :
print("A")
elif score>=80:
print("B")
elif score>=70:
print("C")
elif score>=60:
print("D")
else:
print("F")
print("학점입니다.^^\n")
print("프로그램을 종료합니다")
for i in range(0,3,1): #0으로 시작해서 3사이에 1씩
print("Hello")
for i in [0,3,1]: #0으로 시작해서 3사이에 1씩
print("Hello")
Hello
Hello
Hello
for i in range(0,6,1): #0으로 시작해서 6사이에 1씩
print("%d"%i) #"십진수의 형태로" i 값을 불러온다
3
4
5
for i in [0,1,2,3,4,5,6,7,8,9]: #배열지정
print("%d"%i)nbsp; #"십진수의 형태로" i 값을 불러온다
0
3
4
5
6
7
8
9
i,hap = 0,0
for i in range(1,11,1):
hap=hap+i
print("1에서 %d 까지의 합 = %d"%(i,hap))
1에서 1 까지의 합 = 1
1에서 2 까지의 합 = 3
1에서 3 까지의 합 = 6
1에서 4 까지의 합 = 10
1에서 5 까지의 합 = 15
1에서 6 까지의 합 = 21
1에서 7 까지의 합 = 28
1에서 8 까지의 합 = 36
1에서 9 까지의 합 = 45
1에서 10 까지의 합 = 55
num = 1
while True:
num = int(input("num : "))
if num == 0:
break
if num == 1:
print("다시 입력")
continue
print(num)
print("0이면 종료")
import random
my_tuple = ("one","two","three","four")
while True:
i=random.randint(0,3)
print(my_tuple[i])
key = int(input("key : "))
if key == 0:
break
print("프로그램 종료")
대괄호로 묶으면 리스트 중괄호로 묶으면 사전 소괄호로 묶으면 튜플
import random
i=0
key=1
my_list = ["one","two","three","four"]
while True:
i=random.randint(0,3)
print(my_list[i])
key = int(input("key : "))
if key == 0:
break
print("프로그램 종료")
대괄호로 묶으면 리스트 중괄호로 묶으면 사전 소괄호로 묶으면 튜플
list값 변경
a_list = [10,20,30,40]
a_list [2] = 300
list값 삭제
a_list = [10,20,30,40]
del(a_list[1])
dictionary
dic_1 = {1:'a',2:'b',3:'c'}
student = {'학번':1000,'이름':'홍길동','학과':'모바일'}
dictionary값 추가/변경
student ['연락처']='010-9406-2682'
dictionary값 삭제
del(student[연락처])
데이터 읽기
student['학번']
list(student.keys())
student.values()
#for문 활용 dictionary값 출력
mobile={} #tuple->().list->[]
mobile['이름']='김수환'
mobile['학번']='130100682'
mobile['주소']='서울 용산구 보광동'
mobile['학점']='A+'
mobile['전화번호']='010-1234-5678'
for mo in mobile.keys():
print('%s ---> %s' %(mo,mobile[mo]))
#함수정의
def calc(num1,num2,op):
result = 0
if op == '+' :
result = num1 + num2
if op == '-' :
result = num1 - num2
if op == '*' :
result = num1 * num2
if op == '/' :
result = num1 / num2
return result
##변수선언
res = 0
var1, var2, oper = 0, 0, ""
###메인코드
#res = calc(10,20,"+")
print(res)
print()
oper = input("연산자 입력(+,-,*,/) : ")
var1 = int(input("num1 값 입력 : "))
var2 = int(input("num2 값 입력 : "))
res = calc(var1,var2,oper)
print("계산기 : %d %s %d = %f "%(var1,oper,var2,res))
def para_func(val_1=0,val_2=0,val_3=0,val_4=0,val_5=0): #매개변수
result = 0
result = val_1+val_2+val_3+val_4+val_5
return result
value = para_func(10,20,30,40,50)
print(value)
150
para_func(10,20,30)
60
#함수의 가변 매개변수
def para_func(*para):
result = 0
for num in para:
result = result + num
return result
hap = para_func(10,20,30)
print(hap)