12,405,895 members (46,951 online)
Rate this:
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.
--SA
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.
--SA
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...
--SA
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?
--SA
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.
--SA

Top Experts
Last 24hrsThis month
 OriginalGriff 351 BillWoodruff 160 ppolymorphe 150 Karthik Bangalore 144 Richard Deeming 125
 OriginalGriff 7,747 ppolymorphe 3,380 Karthik Bangalore 3,321 Richard MacCutchan 2,472 F-ES Sitecore 2,300