Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Iteration with 2 Variables
#1
Hello, This is my first attempt at writing a program using Python and I'm a bit stuck.
I'd like to write the sequence shown in the comments to an Excel spreadsheet. I can do it for just one variable i but get an error (Value Error: Too many values to unpack (Expected 2) when i try to use a second variable j to create a nested loop.
Can anyone help? (Sorry I know this will seem really basic to some)

Here is the code:

import xlsxwriter

workbook = xlsxwriter.Workbook('MyTest.xlsx')
worksheet = workbook.add_worksheet()

row = 0
col = 0

for i,j in range(0,2),(0,2):

    worksheet.write(row, col, i)
    worksheet.write(row, col+1, j)

    row += 1

workbook.close()
#want output
Output:
#00 #01 #02 #10 #11 #12 #20 #21 #22
Reply


Messages In This Thread
Iteration with 2 Variables - by punksnotdead - Apr-10-2019, 04:54 PM
RE: Iteration with 2 Variables - by ichabod801 - Apr-10-2019, 05:46 PM
RE: Iteration with 2 Variables - by punksnotdead - Apr-12-2019, 01:02 PM
RE: Iteration with 2 Variables - by ichabod801 - Apr-12-2019, 04:47 PM
RE: Iteration with 2 Variables - by punksnotdead - Apr-12-2019, 04:58 PM
RE: Iteration with 2 Variables - by Yoriz - Apr-12-2019, 05:03 PM
RE: Iteration with 2 Variables - by punksnotdead - Apr-13-2019, 08:33 AM
RE: Iteration with 2 Variables - by DeaD_EyE - Apr-14-2019, 08:48 AM
RE: Iteration with 2 Variables - by punksnotdead - Apr-14-2019, 11:01 AM

Forum Jump:

User Panel Messages

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