Python Forum
Making a calculator with just the + sign
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Making a calculator with just the + sign
#1
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
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  problem with ‘>’ (i.e. greater than) sign AOCL1234 2 1,900 Jun-30-2020, 09:32 PM
Last Post: Yoriz
  A sign-Reversal Puzzle HY2000 2 2,434 Dec-05-2019, 11:55 AM
Last Post: HY2000
  User sign up and login system tesilstudent112 1 5,050 Oct-22-2017, 10:14 AM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020