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
  Two variables in for loop vipinv23 4 80 11 hours ago
Last Post: ndc85430
  Com Error with macro within for loop due to creating new workbook in the loop Lastwizzle 0 141 May-18-2019, 09:29 PM
Last Post: Lastwizzle
  labelling variables of df with map() in loop theinzawoo 2 238 Mar-19-2019, 03:42 AM
Last Post: theinzawoo
  Question about for loop not creating an infinite loop. FWendeburg 1 303 Feb-03-2019, 08:45 PM
Last Post: ichabod801
  I need help with loop one function and creating variables don 3 362 Jan-24-2019, 07:31 AM
Last Post: buran
  Confused by order of operations ward 4 288 Jan-22-2019, 08:53 PM
Last Post: Larz60+
  loop through list or double loop 3Pinter 4 511 Dec-05-2018, 06:17 AM
Last Post: 3Pinter
  while loop issue - stuck in the loop! EricMichel 6 838 Aug-06-2018, 03:59 PM
Last Post: EricMichel
  Float operations not working after cross-compilation tfgdt 0 578 Jul-09-2018, 05:59 PM
Last Post: tfgdt
  I can't figure out how to create variables in a while loop MrCag 1 507 May-08-2018, 08:56 PM
Last Post: wavic

Forum Jump:


Users browsing this thread: 1 Guest(s)