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
#2
What are you supposed to log?
Reply
#3
Your functions all seem to take *args but never use that.

Also, after you compute the result on line 50, you aren't printing anything.
Reply
#4
(Nov-25-2020, 04:18 AM)deanhystad Wrote: What are you supposed to log?

I made simple calculator but now i got the assignment to improve it. Unfortunately, no one explained to me how to do it. All I know is to use "logging" and instead of two numbers it will be possible to use more numbers for the calculation. My previos calc below:
# adds two numbers def add(x, y): return x + y # subtracts two numbers def subtract(x, y): return x - y # multiplies two numbers def multiply(x, y): return x * y # divides two numbers def divide(x, y): return x / y print("Select operation.") print("1.Add") print("2.Subtract") print("3.Multiply") print("4.Divide") while True: # Take input from the user choice = input("Enter choice(1/2/3/4): ") # Check if choice is one of the four options if choice in ('1', '2', '3', '4'): num1 = float(input("Enter first number: ")) num2 = float(input("Enter second number: ")) if choice == '1': print(num1, "+", num2, "=", add(num1, num2)) elif choice == '2': print(num1, "-", num2, "=", subtract(num1, num2)) elif choice == '3': print(num1, "*", num2, "=", multiply(num1, num2)) elif choice == '4': print(num1, "/", num2, "=", divide(num1, num2)) break else: print("Invalid Input")
Reply


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

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.