Making a calculator with just the + sign - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Making a calculator with just the + sign (/thread-7982.html) |
Making a calculator with just the + sign - gerardmanken - Feb-01-2018 Hey everyone! I just started programming in Python some weeks ago and I'm stuck with some homework. We are asked to create a calculator which could add, subtract, multiply and divide but we are just allowed to use additions. That means, no -, * o : sign. Plus, we cannot use operations provided by the programming language (the operator for example). However, we are allowed to use an increment operator (++), and logical operators. For now, I've been able to make the addition part (the most obvious...) but I don't know where to start for the others, especially for the divide and subtract parts. For the multiplying, I thought about doing a function that sums a number x times. For example, 5*4 is 5+5+5+5. Well, if someone could give me a hint (without doing it for me, obviously, we are here to learn!) that would help me! Thanks a lot, GĂ©rard RE: Making a calculator with just the + sign - buran - Feb-01-2018 for the division - obviously this works only for numbers that one is exact multiple of the other. so to find m/n make a loop adding n one at a time and counting how many iterations will be necessary to reach m. more or less for m-n. make a loop adding 1 to n and count how many iterations will be required to reach m. |