I am trying to make a python calculator. It works until it tries to calculate. The calculation gives a blank output. I tried making some variables global but that did not work. I am running out of ideas. Please answer if you know what my mistake is. This is my code:
#import getpass module to get windows username
import getpass
#import time module for delays
import time
#function that sets value1 and value2
def userinput():
global text1
global text2
num1 = int(input(text1))
num2 = int(input(text2))
global num1
global num2
#function that adds input values
def add(num1, num2):
global text1
global text2
return num1 + num2
#function that subtracts input values
def subtract(num1, num2):
return num1 - num2
#function that multiplies input values
def multiply(num1, num2):
return num1 * num2
#function that devides input values
def devide(num1, num2):
return num1 / num2
#gets user input and looks for invalid input
def calculator():
name = getpass.getuser()
print("Hello", name)
operation = input("Wat wil je doen: - aftreken, + optellen, * vermeningvuldigen, / delen ")
if(operation != '-' and operation != '+' and operation != '*' and operation != '/'):
print("Het symbool dat u getypt hebt stond was niet genoemd")
time.sleep(1)
operation = input("Wat wil je doen: - aftreken, + optellen, * vermeningvuldigen, / delen ")
else:
#if "-" was choosen
if(operation == '-'):
text1 = "Bij welk nummer moet er wat worden afgetrokken?"
text2 = "Wat wordt er van afgetrokken?"
userinput()
subtract(num1, num2)
#if "+" was choosen
if(operation == '+'):
text1 = "Bij welk nummer moet er wat bij komen?"
text2 = "Wat wordt komt er bij?"
userinput()
add(num1, num2)
#if "*" was choosen
if(operation == '*'):
text1 = "Bij welk nummer moet vermeningvuldigd worden?"
text2 = "Hoe vaak?"
userinput()
multiply(num1, num2)
#if "/" was choosen
if(operation == '/'):
text1 = "Bij welk nummer moet gedeeld worden?"
text2 = "Door wat?"
global text1
global text2
userinput()
devide(num1, num2)
calculator()