 Simple Calculation | Sololearn: Learn to code for FREE!

+1

# Simple Calculation

#This is the combined code from the previous lessons for the calculator, but the user inputs should be words and numbers or first words then numbers. Please spot the erorr and let me know why by commenting within the code using the hash symbol. while True: print("Options:") print("Enter 'add' to add two numbers") print("Enter 'subtract' to subtract two numbers") print("Enter 'multiply' to multiply two numbers") print("Enter 'divide' to divide two numbers") print("Enter 'quit' to

+1

Here's the full code. You should know that this won't run on sololearn due to the infinite while loop (it will cause an error), so better run on a computer. First input the words and then the numbers. The code seems pretty straightforward, try reading it once again here.(Edit: Added non-commented version for easy code-reading) https://code.sololearn.com/cE4FmYcHvtwH/?ref=app https://code.sololearn.com/c4PPD3tDNhDU/?ref=app

+2

The thing is when you run it on a computer it runs on *your* computer but when you run on sololearn the code and user inputs are sent to sololearn's server and it runs there.After running the output of the code is sent back to you. So there isn't any long lasting connection between sololearn and its server to run an infinite loop. And so is true for any other websites (sorry I am not aware of any website where you can run the code) Here's a simple code that shows that the code in fact runs on a server rather than your device... https://code.sololearn.com/cSFnJNrHz77B/?ref=app

+1

Danigamy so what is the different between the app and the computer? Shouldn't they be the same? Is it possible to run it online using a website instead of download the software? Thanks

0

It seems that the code is not fully there. this is the full one while True: print("Options:") print("Enter 'add' to add two numbers") print("Enter 'subtract' to subtract two numbers") print("Enter 'multiply' to multiply two numbers") print("Enter 'divide' to divide two numbers") print("Enter 'quit' to end the program") user_input = input(": ") #check where to place this code elif user_input == "add": num1 = float(input("Enter a number: ")) num2 = float(input("Enter another number: ")) elif user_input == "add": num1 = float(input("Enter a number: ")) num2 = float(input("Enter another number: ")) result = str(num1 + num2) print("The answer is " + result) #till here elif user_input == "subtract": num1 = float(input("Enter a number: ")) num2 = float(input("Enter another number: ")) result = str(num1 - num2) print("The answer is " + result) elif user_input == "multiply": num1 = float(input("Enter a number: ")) num2 = float(input("Enter another number: ")) result = str(num1 * num2) print("The answer is " + result) elif user_input == "divide": num1 = float(input("Enter a number: ")) num2 = float(input("Enter another number: ")) result = str(num1 / num2) print("The answer is " + result) if user_input == "quit": break elif user_input == "add": ... elif user_input == "subtract": ... elif user_input == "multiply": ... elif user_input == "divide": ... else: print("Unknown input")