<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>
<Below this line, add a link to the EXACT exercise that you are stuck at.>
<In what way does your code behave incorrectly? Include ALL error messages.>
<What do you expect to happen instead?>
How would you make the code below to “restart” in case the else statement is executed? The console stops in my case when the else statement is executed but I want the code to start a fresh and prompt the user to type the given instructions and nothing else. What code should I add? Thanks
```python
#basic calculator
print (“OPTIONS”)
print (“Type ‘multiply’ to multiply two numbers”)
print (“Type ‘divide’ to devide two numbers”)
print (“Type ‘add’ to add two numbers”)
print (“Type ‘subtract’ to subtract two numbers”)
print (“Type ‘quit’ to Quit”)
I can see you’ve put in new codes that I am not quite familiar with.Could you please explain what this line does? [quote=“mtf, post:2, topic:47846”]
("\n> {0} + {1} = {2}\n".format(num1, num2, result))
[/quote]
why did you use command() as value of user_input? Thanks
options = ("=" * 40) + \
"""
OPTIONS
Type 'multiply' to multiply two numbers
Type 'divide' to devide two numbers
Type 'add' to add two numbers
Type 'subtract' to subtract two numbers
Type 'quit' to Quit
"""
input_error = "Input Error! Try again..."
def command():
global options
print (options)
return input("Command: ")
def writeln(x1, x2, y):
print ("\n> {0} + {1} = {2}\n".format(x1, x2, y))
def inputln(prompt):
while True:
try:
return float(input(prompt))
except ValueError:
print (input_error)
But I see where I messed up. Working on a solution, as I hope you are, also.
Update…
New working code.
options = ("=" * 40) + \
"""
OPTIONS
Type 'multiply' to multiply two numbers
Type 'divide' to devide two numbers
Type 'add' to add two numbers
Type 'subtract' to subtract two numbers
Type 'quit' to Quit
"""
input_error = "Input Error! Try again..."
def command():
global options
print (options)
return input("Command: ")
def writeln(x1, p, x2, y):
print ("\n> {0} {1} {2} = {3}\n".format(x1, p, x2, y))
def inputln(prompt):
while True:
try:
return float(input(prompt))
except ValueError:
print (input_error)