def add(n1,n2):
return n1 + n2
def subtract(n1,n2):
return n1 - n2
def multiply(n1,n2):
return n1 * n2
def devide(n1,n2):
return n1 / n2
operations = {"+":add,
"-":subtract,
"*":multiply,
"/":devide,
}
programrun = True
while programrun:
first_number = float(input("What's the first number?: "))
print("+")
print("-")
print("*")
print("/")
picked_operation = input("Pick an operation: ")
next_number = float(input("What's the next number?: "))
answer = operations[picked_operation](first_number,next_number)
print(f"{first_number} {picked_operation} {next_number} = {answer} ")
again = input(f"Type 'y' to continue calculating with {answer}, or type 'n' to start a new calculation, or type 'q' to quit: ")
if again == 'q':
print("Good bye!")
programrun = False
if again == 'n':
answer = 0
elif again == 'y':
for symbol in operations:
new_firstnum = answer
print("+")
print("-")
print("*")
print("/")
picked_operation = input("Pick an operation: ")
next_number = float(input("What's the next number?: "))
answer = operations[picked_operation](answer,next_number)
print(f"{new_firstnum} {picked_operation} {next_number} = {answer} ")
new_firstnum = answer
again = input(f"Type 'y' to continue calculating with {answer}, or type 'n' to start a new calculation, or type 'q' to quit: ")
if again == 'q':
print("Good bye!")
programrun = False
왜 위에서만 new_firstnum = answer 하면 이상하게 출력되는지 모르겠다
'python study' 카테고리의 다른 글
| 파이썬 간단한 해시값 무결성 검사 (0) | 2025.09.21 |
|---|---|
| 파이썬 turtle로 거북이 경주시키기 (0) | 2024.09.29 |
| 파이썬으로 블랙잭 만들기 (2) | 2024.09.08 |
| Python으로 행맨게임 만들기 (0) | 2024.09.05 |
| 파이썬 공부 1 (0) | 2024.05.21 |