Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MemoryError
#1
First of all Hello guys,

I am quit definitely a newbie in the world of python programming.

I use to do R programming but not really object language.

I think I have read some stuff about my problem before posting another topic, but I cannot fix it by myself.

Here is the problem I have a simple function in python to calculate the flow rates of a pump with the speed and the head.

I have some functions that I have made since curves to approximate the reality.

The problem is that python says : MemoryError

So here is my code :

print ('Enter your Head in feat:')
Head = int(input ())
print ('Enter you speed in rpm')
Speed = int(input()) 

if (2142<= Speed >=2499):
        function = ((2499-Speed)/357)*((-1,75*10**-8)*Head**4+(1,21*10**-4)*Head**3-(3,1*10**-1)*Head**2+(3,53*10**2)*Head-1,49*10**5)+((Speed-2142)/357)*((-2,87*10**-9)*Head**4 +(2,58*10**-5)*Head**3-(8,71*10**-2)*Head**2+(1,3*10**2)*Head-7,03*10**4)
if (2499< Speed >=2856):
        function = ((2856-Speed)/357)*((-2,87*10**-9)*Head**4+(2,58*10**-5)*Head**3-(8,71*10**-2)*Head**2+(1,3*10**2)*Head-7,03*10**4)+((Speed-2499)/357)*((-2,21*10**-9)*Head**4 +(2,67*10**-5)*Head**3-(1,2*10**-1)*Head**2+(2,38*10**2)*Head-1,74)
if (2856< Speed >=3213):
        function = ((3213-Speed)/357)*((-2,21*10**-9)*Head**4+(2,67*10**-5)*Head**3-(1,2*10**-1)*Head**2+(2,38*10**2)*Head-1,74)+((Speed-2856)/357)*((-1,06*10**-9)*Head**4 +(1,65*10**-5)*Head**3-(9,57*10**-2)*Head**2+(2,46*10**2)*Head-2,33*10**5)
if (3213< Speed >=3570):
        function = ((3570-Speed)/357)*((-1,06*10**-9)*Head**4+(1,65*10**-5)*Head**3-(9,57*10**-2)*Head**2+(2,46*10**2)*Head-2,33*10**5)+((Speed-3213)/357)*((-3,77*10**-10)*Head**4 +(7,19*10**-6)*Head**3-(5,12*10**-2)*Head**2+(1,61*10**2)*Head-1,87*10**5)

print('The value is :'+ function )
and I just have MemoryError without anything else ( the debug mode doesn't say anything else ( or I have missed something))

My laptop is 6 Go RAM and Spyder(my IDE) is 64 bits with linux tara 64 bits

The thing is for me that it seems the code is super bad ( yes I am new ) or I have a something wrong in setting.

Hope I have done a post following all the rules.

Thank you if you have any idea to help me.
Reply
#2
I can't reproduce your issue:
Error:
File "testit.py", line 7 function = ((2499-Speed)/357)*((-1,75*10**-8)*Head**4+(1,21*10**-4)*Head**3-(3,1*10**-1)*Head**2+(3,53*10**2)*Head-1,49*10**5)+((Speed-2142)/357)*((-2,87*10**-9)*Head**4 +(2,58*10**-5)*Head**3-(8,71*10**-2)*Head**2+(1,3*10**2)*Head-7,03*10**4) ^ SyntaxError: invalid token
That said, I would have had to guess a speed and head. Can you please provide simpler code without input() (just hard-coded values which reproduce the issue) and verify that the code you've posted produces a particular error? Also, you should provide the full error message, not just "MemoryError" (if your IDE does not provide this, use a terminal to get it). I expect that you should be able to post five or fewer lines to reproduce this issue, no need to provide 4 similar lines.

Other than that, what type are you expecting function to be?
Reply
#3
If I try any of these I get SyntaxError: invalid token

First rewrite your functions in such a way as they are readable.

Then supply valid values for Head and Speed.

Try again, then post error message verbatim
Reply
#4
Assuming you have locale settings using a comma as a decimal separator, and you use str(function) in the final call to fix that type error, I am not getting a memory error. I'm guessing at what head should be, and I'm giving 3000 as speed, since that is an allowed value. Actually tried several apparent allowed values and noticed your conditionals are all messed up. They should probably be of the form (2142 <= Speed <= 2499). As it is, the first one is equivalent to Speed >= 2499. And since you are not using elifs, you are probably running the calculations multiple times.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#5
Learn how to write literal floating numbers: I think that by -1,75*10**-8 you mean -1.75e-8. Same thing for the other coefficients. In particular, you cannot replace the dot in floating numbers by a comma.
Reply
#6
Thank you so much for your answer in fact you were right it seems that the coma was the problem I remplace it by dot and everything is better.

But the value as 1.5*10**5 is working as the same as 1.5e5 for me.

I've another problem in the code but as it is not the same problem as here I will open a new topic after looking in the forum if anybody had the same.

Hope you will have a good day and thanks again
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  MemoryError in pywinauto.findwindows.find_windows – Need Help! ktw3857 0 117 Mar-25-2024, 02:23 AM
Last Post: ktw3857
  Code starts slowing down? MemoryError AshkanDev 1 2,117 May-19-2020, 11:38 PM
Last Post: AshkanDev
  Getting MemoryError frames.write(buffer) kunwarsingh 0 1,568 Feb-10-2020, 09:39 PM
Last Post: kunwarsingh
  MemoryError AwaAgathe 0 1,699 Feb-26-2019, 02:57 AM
Last Post: AwaAgathe

Forum Jump:

User Panel Messages

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