Hi there, creating new variable to add to a function, and when the user inputs a value, I get this:

ValueError: need more than 2 values to unpack

This is for sizeWindow variable by the way, I'll bold the parts I'm talking about.

from graphics import *

def main():
    doorColour, lightProb, [B]sizeWindow[/B] = getInputs()
    drawHouse(doorColour, lightProb, [B]sizeWindow[/B])

def getInputs():
    doorColour = input("Enter door colour: ")
    lightProb = eval(input("Enter probability of light being on: "))
    [B]sizeWindow = eval(input("Enter the size of the window (in pixels): "))[/B]
    #houseNum = eval(input("Enter the number to be displayed on door:  "))
    return doorColour, lightProb

def drawHouse(doorColour, lightProb, [B]sizeWindow[/B]):
    win = GraphWin("House", sizeWindow, sizeWindow)
    win.setCoords(0, 0, 100, 100)

    roof = Polygon(Point(2, 70), Point(22, 90),
                   Point(78, 90), Point(98,70))
    roof.setFill("pink")
    roof.draw(win)

    # draw wall, chimney and door
    drawRectangle(win, Point(2, 2), Point(98, 70), "brown")
    drawRectangle(win, Point(25, 80), Point(33, 95), "brown")
    drawRectangle(win, Point(42, 2), Point(58, 32), doorColour)

    for x in [20, 80]:
        for y in [20, 55]:
            drawWindow(win, x, y, lightProb)

def drawWindow(win, centreX, centreY, lightProb):
    from random import random
    if random() < lightProb:
        colour = "yellow"
    else:
        colour = "black"
    halfFrameSize = 1
    glassSize = 10
    panelSize = halfFrameSize + glassSize
    for x in [centreX - panelSize, centreX + halfFrameSize]:
        for y in [centreY - panelSize, centreY + halfFrameSize]:
            drawRectangle(win, Point(x, y),
                          Point(x + glassSize, y + glassSize),
                          colour)
    
def drawRectangle(win, point1, point2, colour):
    rectangle = Rectangle(point1, point2)
    rectangle.setFill(colour)
    rectangle.setOutline(colour)
    rectangle.draw(win)

main()

This error happens in the assignment statement when you try to assign the wrong number of values to the wrong number of names, for example

>>> a, b, c = (1, 2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: need more than 2 values to unpack

In your case, getInputs(), returns only 2 values, but the first line in main() tries to assign these 2 values to 3 names.

Edited 5 Years Ago by Gribouillis: n/a

This question has already been answered. Start a new discussion instead.