Dec-17-2020, 08:23 PM
Hello everyone. Below I am sharing the code of a simple working calculator. Program works well but i need to obtain this:
Enter action, select number 1 Addition, 2 Substraction , 3 Multiplication, 4 Division: 1 Enter number 1. 2.3 Enter number 2. 5.4 I add 2.30 and 5.40 Result is 7.70This is my code:
import operator from functools import reduce import logging logging.basicConfig(format='%(asctime)s %(message)s') logging.warning('Time') print() print() # Add def add(numbers): return reduce(operator.add, numbers) # Sub def subtract(numbers): return reduce(operator.sub, numbers) # Multiply def multiply(numbers): return reduce(operator.mul, numbers) # Divide def divide(numbers): return reduce(operator.truediv, numbers) def get_data(): choice = input("Choose operation(1/2/3/4): ") args = [] if choice in "1234": while True: num = input("Choose another number or click q to quit: ") if num == 'q': break args.append(float(num)) return args, choice print("Enter operation, select number:") print("1.Add") print("2.Sub") print("3.Multiply") print("4.Divide") operations = { '1': add, '2': subtract, '3': multiply, '4': divide, } numbers, choice = get_data() result = operations[choice](numbers) print(result)Can someone help me and tell me where and how to put logging in so that it displays what I wrote at the beginning?