1

I have run into an error where a block of code in python 3.7 has caused multiple outputs where one is expected. The code is as follows:

def main():
    length=0;height=0;width=0;volume=0
    length,height,width=getinput(length,height,width)
    volume=processing(length,height,width,volume)
    output(volume)
def getinput(length,height,width):
    length, height, width = input("Enter length, height, and width:").split(',')
    length = int(length)
    height = int(height)
    width = int(width)
    return length,height,width
def processing(length,height,width,volume):
    volume = length * height * width
    return length,height,width,volume
def output(volume):
    print("the volume of the prism is:", volume)
main()

The output should be:

the volume of the prism is: 400

The output is:

the volume of the prism is: (20, 10, 2, 400)
1
  • output prints volume, which comes from processing, which returns length,height,width,volume. Four outputs are expected. If you are expecting one, return volume from processing. Commented Dec 3, 2015 at 4:06

2 Answers 2

1

In your def processing(length,height,width,volume) function, the return statement is return length,height,width,volume which basically means that you are returning a tuple and when you are catching it into a variable called volume, it becomes a tuple. See in the output you have (20, 10, 2, 400). The braces shows that it is a tuple. You can also confirm that by printing type(volume). If you want to get 400 as an answer, please do output(volume[3]).

Sign up to request clarification or add additional context in comments.

Comments

0

You probably meant to do this:

>>> def processing(length,height,width,volume):
...     volume = length * height * width
...     return volume
...
>>> main()
Enter length, height, and width:20, 10, 2
the volume of the prism is: 400

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.