Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # calculator that tests input and keeps adding for ever
- action = input("Insert maths sign (+,-,*,/) = ");
- num1 = int(input("please input number = "));
- loop = 0;
- # loop until a non number is entered
- while loop == 0:
- numX = input("please input number (press enter to end)= ");
- # tests if a number was input
- if numX.isdigit():
- # does maths
- if action == "+":
- num1 = num1 + int(numX);
- elif action == "-":
- num1 = num1 - int(numX);
- elif action == "/":
- num1 = num1 / int(numX);
- elif action == "*":
- num1 = num1 * int(numX);
- else:
- # wrong input
- print("Need a correct maths sign (+,-,*,/)")
- loop = 1;
- else:
- loop = 1;
- print("=", num1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement