Python Forum
Calculator with logging library
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Calculator with logging library
#1
I wrote a calculator but it doesn't count Smile I have to use the logging library but i don't know how. Previously, everything worked without this library, now the program does not count. Please help me in indicating how and where to insert logging
# Task calc

# Add
def add(x, y, *args):
    return x + y
# Sub

def subtract(x, y, *args):
    return x - y
# Miltiply

def multiply(x, y, *args):
    return x * y
# Divide

def divide(x, y, *args):
    return x / y


def get_data():
    choice = input("Choose action(1/2/3/4): ")
    x = float(input("enter number 1: "))
    y = float(input("enter number 2: "))
    args = []
    if choice in "13":
        while True:
            num = input("enter anotehr number or q to quit: ")
            if num  == 'q':
                break
            args.append(float(num))
    
    return x, y, args, choice

print("Enter the action using the appropriate number:")
print("1.Add")
print("2.Substract")
print("3.Multiply")
print("4.Divide")

operations = {
    '1': add,
    '2': subtract,
    '3': multiply,
    '4': divide,
}



x, y, args, choice = get_data()
result = operations[choice](x, y, *args)
After choosing for example first option, addition, i can enter two number but after this, program doesnt count:
Enter the action using the appropriate number:
1.Add
2.Substract
3.Multiply
4.Divide
Choose action(1/2/3/4): 1
enter number 1: 5
enter number 2: 5
enter another number or q to quit: q
Reply


Messages In This Thread
Calculator with logging library - by Inkanus - Nov-24-2020, 10:42 PM
RE: Calculator with logging library - by deanhystad - Nov-25-2020, 04:18 AM
RE: Calculator with logging library - by Inkanus - Nov-25-2020, 02:34 PM
RE: Calculator with logging library - by ndc85430 - Nov-25-2020, 04:26 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  PyInstaller, how to create library folder instead of library.zip file ? harun2525 2 4,849 May-06-2017, 11:29 AM
Last Post: harun2525

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020