4 Replies - 786 Views - Last Post: 08 July 2013 - 08:42 AM Rate Topic: -----

#1 laffy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 08-July 13

Calculating volume

Posted 08 July 2013 - 06:39 AM

Working on code to get volume of cubes...

How do I get user input?

def BV (length=1, height = 1, width = 1):
    """calc box volume"""
    volume = length * height * width  # volume is a local variable
    return volume


Thanks
Is This A Good Question/Topic? 0
  • +

Replies To: Calculating volume

#2 ConciselyVerbose  Icon User is offline

  • D.I.C Regular

Reputation: 90
  • View blog
  • Posts: 315
  • Joined: 05-July 13

Re: Calculating volume

Posted 08 July 2013 - 08:00 AM

What python are you using? For 2.7 and lower, use raw_input(). For 3 and up, input replaces raw_input
Was This Post Helpful? 0
  • +
  • -

#3 laffy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 08-July 13

Re: Calculating volume

Posted 08 July 2013 - 08:23 AM

I'm using 2.7
Was This Post Helpful? 0
  • +
  • -

#4 laffy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 08-July 13

Re: Calculating volume

Posted 08 July 2013 - 08:34 AM

def BV (length=1, height = 1, width = 1):
    """calc box volume"""
    volume = length * height * width  # volume is a local variable
    return volume

length = int(raw_input("Enter box length: "))
height = int(raw_input("Enter box height: "))
width = int(raw_input("Enter box width: "))

Was This Post Helpful? 0
  • +
  • -

#5 ConciselyVerbose  Icon User is offline

  • D.I.C Regular

Reputation: 90
  • View blog
  • Posts: 315
  • Joined: 05-July 13

Re: Calculating volume

Posted 08 July 2013 - 08:42 AM

Yep. You may want to handle bad input, and you need to call the function, but I just tested that (on an ipad with 2.4 or so) and it appears to work as intended.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1