how do i repeat??? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: how do i repeat??? (/thread-1314.html) |
how do i repeat??? - Darbandiman123 - Dec-23-2016 i have some coding that i would like to repeat here is the coding how do i do it??? it is for a calculator and i want to repeat the last bit ("main()") #returns the result of adding num1 + num2 def add(num1, num2): return num1 + num2 #returns the result of subtracting num1 - num2 def minus(num1, num2): return num1 - num2 #returns the result of mutipliying num1 * num2 def multiply(num1, num2): return num1 * num2 #returns the result of dividing num1 / num2 def divide(num1, num2): return num1 / num2 def main(): operation = input("what do you want to do (+,-,*,/): ") if(operation != '+' and operation != '-' and operation != '*' and operation != '/'): #invalid operation print("please enter a vaild operation") else: num1 = int(input("Enter num1: ")) num2 = int(input("Enter num2: ")) if(operation == '+'): print(add(num1, num2)) elif(operation == '-'): print(minus(num1, num2)) elif(operation == '*'): print(multiply(num1, num2)) else: print(divide(num1, num2)) main() RE: how do i repeat??? - j.crater - Dec-23-2016 Hello and welcome to the forum! I see you are already familiar with if/elif/else statements. Next very useful thing to learn can be loops, and there you will also find (at least one) solution for your challenge. Good luck! RE: how do i repeat??? - snippsat - Dec-23-2016 See if you can pick up some hint in my post here. |