Click here to Skip to main content
13,087,235 members (60,011 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I need a solution in python of this

y = 4/1-4/3+4/5-4/7+4/9-4/11...

Not using the If statement
just for loop
Posted 30-Oct-12 11:50am
Sergey Alexandrovich Kryukov 30-Oct-12 18:39pm
Well, if you need it, why not doing it? But first, can you strictly formulate the problem?
Do you know that this "expression" (with ... at the end, aha :-) does not explain it completely, leaves a room for guess.
Sergey Alexandrovich Kryukov 30-Oct-12 18:42pm
And, by the way, why would you think this would require "if" in first place? :-)
Anyway, it looks like a home assignment. It is apparently very, very trivial, but you should do your home assignments by yourself, we won't do it for you.
Diar Selimi 30-Oct-12 18:53pm
Well im a begginer in Programming and im not good in math ,so im trying to understand from the others how they do it . but thnx anyway , i will try by my self first then i will ask you for more
Sergey Alexandrovich Kryukov 30-Oct-12 19:08pm
Well, then please do it first. By the time you come back, devise comprehensive and formal description of the mathematical problem. You don't want infinite number of iterations, right? After all, what's the problem? This is just a loop...
Diar Selimi 30-Oct-12 19:20pm
yeahh it's just a loop but it has to be the operator first - than + than the denominator should always be an odd , and it's not a infinite number is based on what is the input .
Sergey Alexandrovich Kryukov 30-Oct-12 19:31pm
OK, I understand that, but, for your own good, you should better be able to correctly formulate things, without any ambiguity. You could do it on mathematically strict level, or just, less formally, as a signature of the functions with explanation of meaning of all inputs and outputs.

Now, about + and -. Now you are moving in right direction. The denominator is some -N or +N, depending on N. You can check if it's odd and write "if", but you are required to use only arithmetic operators, right? And what, do you think there is no arithmetic operators to give - or + in different cases? If not operator, it could be an expression using more then one operator, right? So, now the school arithmetic stuff comes into play... what can it be?
Sergey Alexandrovich Kryukov 30-Oct-12 19:10pm
I think you are confused with changing sign of the terms. Here is the hint: the algorithm only requires middle-school mathematics. No calculus or something advanced.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.170813.1 | Last Updated 30 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100