Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Operations on indexed variables in loop
#1
Hello,
Beginner in Python and having spent about 4 hours in this very simple operation, I now rely on your expertise. I'm used to Javascript and in JS you can when you have sets of variables defined (say they're array or matrices), create a loop on those variables indexes to create new ones.
The input variables are defined such as v1, v2, v3, ..., v10 and I want to create new variables such as v11, v12, ..., v20; using the numbers in the name of the variables in the loop index
in my language it'd be:
for i in range (0,10):
	v[i+10]=v[i]/2
Must precise that I'm using Python code into an embedded software so it knows what are the v1, v2, etc...
Any idea what's wrong in here?
Many thanks!
Quote
#2
(Aug-14-2019, 05:36 AM)Fibulavie Wrote: Any idea what's wrong in here?

All is wrong. You don't need to create a lot of the same variables, just use lists or dictionaries instead. Every book I read explains lists and dicts on the first ten pages.
buran likes this post
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Indexed position editing of a lst ShruthiLS 4 195 Sep-26-2019, 09:23 AM
Last Post: perfringo
  Two variables in for loop vipinv23 9 466 Aug-26-2019, 05:30 AM
Last Post: newbieAuggie2019
  labelling variables of df with map() in loop theinzawoo 2 393 Mar-19-2019, 03:42 AM
Last Post: theinzawoo
  I need help with loop one function and creating variables don 3 502 Jan-24-2019, 07:31 AM
Last Post: buran
  Confused by order of operations ward 4 456 Jan-22-2019, 08:53 PM
Last Post: Larz60+
  I can't figure out how to create variables in a while loop MrCag 1 618 May-08-2018, 08:56 PM
Last Post: wavic
  Exponentiation order of operations Slatye 6 1,871 Oct-10-2017, 07:49 PM
Last Post: nilamo
  Need my program to run concurrent operations cygnus_X1 1 1,132 Jul-21-2017, 10:49 PM
Last Post: Larz60+
  modulo and order of operations freakbot 4 1,749 Dec-28-2016, 10:30 PM
Last Post: nilamo
  Loop thru textfile, change 3 variables for every line herbertioz 11 3,499 Nov-10-2016, 04:56 PM
Last Post: Larz60+

Forum Jump:


Users browsing this thread: 1 Guest(s)