Python Forum

Full Version: Creating Vector from a Program
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello everyone.
I am a new programmer.
I am trying to create a vector called "pressure", below is an example for the calculations that I have been trying to do.
Below is just a small piece from my code, which is the part that I am trying to solve. Also I simplified the "formula".


 
pressure = []

i = 1
    p0 = 50
    pcp0 = 20
    n = 10
    while i < n:
        p1 = p0 - 0.17 * pcp0
    for pressure in i:
        pressure.append(p1)
        i = i + 1
        p0 = p1 
The error is for pressure in i:
TypeError: 'int' object is not iterable
(Oct-08-2019, 02:48 AM)ericvrocha Wrote: [ -> ]I am trying to create a vector called "pressure", below is an example for the calculations that I have been trying to do.

 
pressure = []

i = 1
    p0 = 50
    pcp0 = 20
    n = 10
    while i < n:
        p1 = p0 - 0.17 * pcp0
    for pressure in i:
        pressure.append(p1)
        i = i + 1
        p0 = p1 
The error is for pressure in i:
TypeError: 'int' object is not iterable

Hi!

I find your code a bit strange.

First, your indentation seems to be wrong.

Second, we learnt at high school that a vector has 1 component if the vector is on a line, like v = (v1), 2 components if the vector is on a plane, like v = (v1, v2) and 3 components if the vector is in space, like v = (v1, v2, v3). I think you are trying to add 9 elements to your vector named 'pressure', from value i = 1 (line 3) to value i = 9 (lines 6, 7 and 11).

Third, your line 9:

for pressure in i:
has no sense to me, because it is just a single value at a time.

Fourth, on your line 8:

p1 = p0 - 0.17 * pcp0
p0 is a constant (p0 = 50), pcp0 is a constant (pcp0 = 20), so p1 is also a constant (p1 = (50) - (0.17 * 20) = 50 - 3.4 = 46.6) (it's independent of 'i' values, and it's not going to change).

Fifth, p0 = p1, is after what you intend to be a loop, so it's not going to change values in the loop either.

All the best,
ericvrocha Wrote:I am trying to create a vector called "pressure"
Can you describe which values the vector is supposed to contain?

newbieAuggie2019 Wrote:we learnt at high school that a vector has 1 component ...
It is true but in general a vector can have as many components as one wants. Such vectors simply live in higher dimensional spaces.
(Oct-08-2019, 07:20 AM)Gribouillis Wrote: [ -> ]
newbieAuggie2019 Wrote:we learnt at high school that a vector has 1 component ...
It is true but in general a vector can have as many components as one wants. Such vectors simply live in higher dimensional spaces.
Thank you!

Here I'm learning many things, among them, that one cannot take as eternal truths, things that you have been taught by your teachers, or even things that you have been reading in supposedly good specialistic books.

Thanks again for enlightening me!

All the best,