I have 2 separate python files one is my code for print statements and other code the other file is for my functions. I import the Mylib file. I'm having a problem with getting it to work properly I need to get these outputs to happen. I just can't seem to get the top output to show up with the bottom output. I can get it do everything but the scalc part. I'm a beginner with python and still learning.
scalc("20,30,*")
the result will be 600
The Result of 15.0+17.0=32.0
The Result of 15.0-17.0=-2.0
The Result of 15.0*17.0=255.0
The Result of 15.0/17.0=0.882352941176
Continue Looping Y/N Y
****Update****
I have it all working now just getting None after the equals instead of a number for example I'm getting
the result of 30 + 9 = None Just a little confused on why I'm getting None
scalc("20,30,*")
the result will be 600
The Result of 15.0+17.0=32.0
The Result of 15.0-17.0=-2.0
The Result of 15.0*17.0=255.0
The Result of 15.0/17.0=0.882352941176
Continue Looping Y/N Y
from Mylib import add, subtract, multiply, divide cont = "Y" while cont == "Y" or "y": # Implemented try except in the ranges. # Why so the user can only input numbers and only in the -100 to 100 range while True: try: loRange = int(input('Enter your Lower range: ')) except ValueError: print ("Enter a number in the range of -100 to 100") else: if -100 <= loRange <= 100: break else: print ("Enter a number in the range of -100 to 100") while True: try: hiRange = int(input('Enter your Higher range: ')) except ValueError: print ("Enter a number in the range of -100 to 100") else: if -100 <= hiRange <= 100: break else: print ("Enter a number in the range of -100 to 100") while True: try: number_1=int(input("Enter your first number:")) except ValueError: print ("Enter a number in the range of -100 to 100") else: if -100 <= number_1 <= 100: break else: print ("Enter a number in the range of -100 to 100") while True: try: number_2=int(input("Enter your second number:")) except ValueError: print ("Enter a number in the range of -100 to 100") else: if -100 <= number_2 <= 100: break else: print ("Enter a number in the range of -100 to 100") print('The Result of', number_1, '+' ,number_2, '=', add(number_1,number_2)) print('The Result of', number_1, '-' ,number_2, '=', subtract(number_1,number_2)) print('The Result of', number_1, '*' ,number_2, '=', multiply(number_1,number_2)) print('The Result of', number_1, '/' ,number_2, '=', divide(number_1,number_2)) cont = input("Continue Looping Y/N: ") print('Thanks for using our calculator!')
#Mylib def add(x, y): return x + y def subtract(x, y): return x - y def multiply(x, y): return x * y def divide(x, y): try: return x / y except ZeroDivisionError: return "You cannot divide by zero" def scalc(p1): astring = p1.split(",") number_1 = int(astring[0]) number_2 = int(astring[1]) if astring[2] == "+": add(number_1, number_2) elif astring[2] == "-": subtract(number_1, number_2) elif astring[2] == "*": multiply(number_1, number_2) elif astring[2] == "/": divide(number_1, number_2) return number_1, number_2 p1 = input("Enter two numbers and an operator, each separated by a comma: ") scalc(p1)
****Update****
I have it all working now just getting None after the equals instead of a number for example I'm getting
the result of 30 + 9 = None Just a little confused on why I'm getting None