β 1λ² μ λ ₯μμ κ³μ° / 2λ² λμ μ¬μ΄μ ν©κ³
select, answer, numStr, num1, num2 =0,0,"",0,0
select = int(input("1.μ
λ ₯νμμ κ³μ° , 2. λμ μ¬μ΄μ ν©κ³ : "))
if select == 1:
numStr = input(' ** μμμ μ
λ ₯νμΈμ : ')
answer = eval(numStr)
print("%s κ²°κ³Όλ %5.1fμ
λλ€." % (numStr,answer))
elif select == 2:
num1 = int( input(' ** 첫λ²μ§Έ μ«μ μ
λ ₯ : '))
num2 = int( input(' ** λλ²μ§Έ μ«μ μ
λ ₯ : '))
for i in range (num1, num2+1, 1) :
answer += i
print("%d+~+%dλ%d μ
λλ€." % (num1,num2,answer))
else :
print("1λλ 2λ§ μ
λ ₯νμΈμ.")
β κ³μ μ λ ₯ν μ μκ²νκΈ° / μ’ λ£λ²νΌ μΆκ°
β οΈμ£Όμν μ
κ³μ ν΄μ κ°μ μλ‘ λ°μΌλ―λ‘ answer κ°μ μ€κ°μ€κ° μ΄κΈ°νλ₯Ό ν΄μ€μΌν¨.
select, answer, numStr, num1, num2 =0,0,"",0,0
while (True) :
select = int(input("1.μ
λ ₯νμμ κ³μ° , 2. λμ μ¬μ΄μ ν©κ³ 3. μ’
λ£ :"))
if select == 1:
answer = 0
numStr = input(' ** μμμ μ
λ ₯νμΈμ : ')
answer = eval(numStr)
print("%s κ²°κ³Όλ %5.1fμ
λλ€." % (numStr,answer))
elif select == 2:
answer = 0
num1 = int(input(' ** 첫λ²μ§Έ μ«μ μ
λ ₯ : '))
num2 = int(input(' ** λλ²μ§Έ μ«μ μ
λ ₯ : '))
for i in range (num1, num2+1, 1) :
answer += i
print("%d+..+%dλ %d μ
λλ€." % (num1,num2,answer))
elif select == 3:
print(" μ’
λ£ ")
break;
else :
print("1λλ 2λ§ μ
λ ₯νμΈμ.")