Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python for next loop
#1
I am new to python and trying to code for the below logic but not sure how to do it using for next loop

Colum1 Colum2 col 3 Col4
1234 111 Str1 50
1234 112 Str2 -50
5677 113 Str3 110
6789 114 Str1 50
6789 114 Str2 -30
6789 114 Str3 10
1456 115 Str1 -100
1456 115 Str2 50
1456 115 Str3 40
1456 115 Str4 -10

Str1 is considered as higher and goes lower based on sequence str2, str3, str4

If the col4 is negstive it can offset where the negative number has the same or lower Str relative to the positive value

like say for col 2 - 114 and col 1 = 6789 -
If Str1 is positive then it can offset with Str 2, Str 3 or Str 4 so the revised value should be 30 for Col 1 = 6789 and Col 2= 114

Say for Col 2 = 115
Str 1 is negative but it cannot offset with Str 2 or St3 or Str 4 but Str4 can offset its negative with any other Str 2 or Str3
So there is two values for Col2 = 115 and can be separated in two columns based on sign.
a) -100
b) 80

I am not sure how to write this sequence for loop in python.

Any help would be highly appreciated.
Reply
#2
Help us to help you. Make an effort by writing code and ask questions if you are stuck.

But before you start coding make sure that you have clarity in your mind, especially about what you have and what you want accomplish.

My feedback on your problem description:

- I read your description of the problem and I am no wiser.
- What is your input data? You read from csv file? From some other datastructure?
- What is the expected output type? List of lists? List of dictionaries? Writing to file?
- Description on terms and conditions is presented in a way that is hard to comprehend (at least for me). If you describe your problem in more structured way you will probably understand it much better.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Forum Jump:

User Panel Messages

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