Feb-20-2018, 12:33 AM
Hi All,
I am 24 hours into Python37 coding using IDLE and have written a calculator script. The calc script should request 2 variables and what needs done with them +-*/. Nothing shows when I run it in Python, it doesn"t ask any of the questions. Script is written off a youtube lesson. Any help would be appreciated. Sorry, when I edit the text all the indents are there and when I save it they all disappear. Any reason for this?
I am 24 hours into Python37 coding using IDLE and have written a calculator script. The calc script should request 2 variables and what needs done with them +-*/. Nothing shows when I run it in Python, it doesn"t ask any of the questions. Script is written off a youtube lesson. Any help would be appreciated. Sorry, when I edit the text all the indents are there and when I save it they all disappear. Any reason for this?
#returns the sum of num1 and num2 def add(num1, num2): return num1 + num2 #returns sum of subtracting num1 and num2 def sub(num1, num2): return num1 - num2 #returns sum of num1 * num2 def mul(num1, num2): return num1 * num2 #returns sum of num1 / num2 def div(num1, num2): return num1 / num2 def main(): #Shouldn't there be something between the brackets?(easier than writing parentisis) operation = input("What do you want to do (+,-,*,/):") if (operation != '+' and operation != '-' and operation != '*' and operation != '/'): #invalid operation print('You must enter a valid operation') else: var1 = int(input("Enter number1:")) var2 = int(input("Enter number2:")) if(operation == '+'): print(add(var1,var2)) elif(operation == '-'): print(sub(var1 - var2)) elif(operation =='*'): print(mul(var1 * var2)) else: print(div(var1 / var2))