[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math


View post   

File: 44 KB, 286x364, python-logo-glassy.png [View same] [iqdb] [saucenao] [google]
5562772 No.5562772 [Reply] [Original]

I want to make myself believe that there are still solid programmers at /sci/.

So here's my problem. I want the following chunk of code (in phyton) to print out 29157.09, but it prints out 29643.043 instead.

I think the problem's rooting from the programs lack of ability to continue it's bisection search in a narrower range.

balance = 320000
annualInterestRate = 0.2
Monthlyinterestrate = (annualInterestRate) / 12.0
n = 12
low = balance / 12.0
high = (balance*(1+Monthlyinterestrate)**12)/12.0
lowestPayment = 0
ubalance = 0
nbalance = balance

while abs(nbalance) > 0.01:
nbalance = balance

for turn in xrange(n):
ubalance = nbalance - lowestPayment
nbalance = ubalance + (Monthlyinterestrate * nbalance)
print nbalance
if nbalance >= 0.001:
low = lowestPayment
elif nbalance <= 0.001:
high = lowestPayment
lowestPayment = (low + high)/2.0
print "Lowest payment: ", round(lowestPayment,3)

>> No.5562780

print(29157.09)

>> No.5562823

> I want to make myself believe that there are still solid programmers at /sci/.

> python

Here are the kinds of programmers on /sci/:
1) C++ fanatics. I don't even

2) People who think you should learn C as a first language. Charming but misguided.

3) People who are learning Java in school. Obviously they may be ignored.

4) People who think python is a good language. Obviously they may be ignored.

5) People who suggest excellent languages like haskell, ocaml, racket, scheme, common lisp, and forth, but recognize the value of learning C later. 10/10, would have sex with. No homo.

6) Anti-language-war posters that hold the opinion that choice of language somehow doesn't matter. One wonders how they explain the fact that different languages exist and are in wide use and continue to be developed, but they'd never answer you because it would mean participating in a language war. Basically the programming equivalent of the "everyone's opinions are equally valid" wishy-washy bullshit. Can be ignored, but they often know many languages and can be helpful on specific points.

Hope this helps!

>> No.5562827

>>5562823
>Hope this helps!
In which possible way would you suppose it does?

>> No.5562843

would be nice if I could see this tabbed

>> No.5562865

would be nice if you had a problem statement instead of your shitty code which is obviously doing exactly what it says

>> No.5562888

>>5562823
>says excellent languages
>recites two programming paradigms, oriented to mathematicians
>fails to acknowledge the n°1 rule of IT: there's not a "best" but "best for"
ok come back in 5 years

>> No.5562893

>>5562888
Hi, (6)!

>> No.5562898

>>5562888
>best for
There's a Lisp macro and a Haskell monad for that, too.

>> No.5562914
File: 45 KB, 256x284, heart.png [View same] [iqdb] [saucenao] [google]
5562914

>>5562898

>> No.5562985

>>5562823

No one who ever says that one language is better that another is a real programmer. They're an idiot who wanna seem smarter than someone else by talking about obscure languages. Kinda like a hipster.

A real programmer could say that one language is better than another for a specific purpose and for the purpose in this thread the languages you listed are shit. Python is the best choice for this particular purpose.

>> No.5563009

>>5562772

As for this question I would love to help you but its a little difficult to figure out what belongs to which loop as tabs are not shown. If you can find a way to show tabs with dashes or something that would be mroe helpful and I could resolve the issue.

>> No.5563034

>>5562985

Correction: Maybe not the BEST but certainly a good one.

>> No.5563049

>>5562985
good lord do i know the type; at my uni you can find those "omg TSQL sucks PSQL is da best!!!" manchildren everywhere. i remember i got into a discussion with this guy because he was arguing that c# was a shit language and he was so butthurt about it he kept muttering under his breath stuff while i tried to get on with my work.
jesus fucking christ, never be that guy

>> No.5563050

>>5562772

Without figuring out what your code does, I'm guessing that your issue is that you want higher precision floating point numbers?

Try numpy or the following:

http://pythonhosted.org/bigfloat/

>> No.5564795

>>5562985
> no true scotsman
butthurt C++ fan detected

>> No.5564821

>>5562985

PHP

>> No.5564833

> OP never came back, never stated his problem, nothing
python programmers lel

>> No.5564849

>>5562772
This is the ugliest fucking code I ever saw, excluding its appearance on 4chan.

>Thread about 'quality' programming
>Python

Cute.

>> No.5564852

>>5562823
>3) People who are learning Java in school. Obviously they may be ignored.

A lot of us don't have a choice, and syntactically its pretty much Identical to C#, one of the undisputed kings of UI development and a great explanation of OOP paradigms.

I've heard strong arguments that the best way to understand OOP is in Java through (near exclusively) the BlueJay IDE.

>> No.5564879

>>5564852
You misunderstand. I have no problem with Java. It's quite good, as far as OOP-centric languages go. It's just the "First Course in Java" kids that may be ignored.

> C#
C# has some good ideas. Bit by bit "industry" programmers are being forced, against their will, to learn about good programming models. Lisp will be there for them when they're ready, like it always has been, as patient as Harriet, and twice as lovely.

>> No.5564885

>>5564852
>BlueJ is a shit IDE and all it does is draw a bootleg UML diagram, Java also sucks and just cause you learn java in school doesn't mean you can't learn any other languages.