Python - is this loop correct? -


def add(num1, num2):     return num1 + num2  def sub(num1, num2):     return num1 - num2  def multi(num1, num2):     return num1 * num2  def div(num1, num2):     return num1 / num2  print("\t\t\tcalculator app")  def main():     operation = input("\nwhat want do: (+, -, *, /)? ")     if(operation != "+" , operation != "-" , operation != "*" , operation != "/"):        #invalid operation        print("you have entered invalid key")     else:        var1 = int(input("please number : "))        var2 = int(input("please enter number : "))        if(operation == "+"):            print("answer is: ", add(var1, var2))        elif(operation == "-"):            print("answer is: ", sub(var1, var2))        elif(operation == "*"):            print("answer is: ", multi(var1, var2))        else:            print("answer is: ", div(var1,var2))  main()  rerun = input("rerun? (y/n)")  while(rerun == "y"):     main()     rerun = input("rerun? (y/n) ")  else:     exit() 

reading books, watching videos, , self study has been challenging.

please let me know if correct way loop program, i'm sure there alternatives.

if mean rerun loop down @ bottom, following cleaner:

while true:     main()     if input("rerun? (y/n) ") == 'n':         break 

it should noted defaults rerunning if user enters not expected.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -