Question regarding int

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ncharman
    New Member
    • Oct 2008
    • 3

    Question regarding int

    x = input ("Number of Guests: ")
    y = input ("Number of beers: ")
    print "Full beers per person: " + str(float(y / x))
    print "Left over beers: " + str(y % x)
    print "Poured into keg and shared: " + str(int(y / x, 3)) +" beer per person"

    this is my current python code, i am attempting to get the poured into keg portion to display 3 decimal places but keep getting an error.

    Traceback (most recent call last):
    File "D:/Charman/GeoProcessing/A2/BeerCalc.py", line 5, in -toplevel-
    print "Poured into key and shared: " + str(int(y / x, 3)), +" beer per person"
    TypeError: int() can't convert non-string with explicit base

    I have been searching and searching for some user friendly advice or tips and I am not too formidable in this language, if anyone can give me some clarification on what im doing wrong I would greatly appreciate it.

    thanks
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Originally posted by ncharman
    x = input ("Number of Guests: ")
    y = input ("Number of beers: ")
    print "Full beers per person: " + str(float(y / x))
    print "Left over beers: " + str(y % x)
    print "Poured into keg and shared: " + str(int(y / x, 3)) +" beer per person"

    this is my current python code, i am attempting to get the poured into keg portion to display 3 decimal places but keep getting an error.

    Traceback (most recent call last):
    File "D:/Charman/GeoProcessing/A2/BeerCalc.py", line 5, in -toplevel-
    print "Poured into key and shared: " + str(int(y / x, 3)), +" beer per person"
    TypeError: int() can't convert non-string with explicit base

    I have been searching and searching for some user friendly advice or tips and I am not too formidable in this language, if anyone can give me some clarification on what im doing wrong I would greatly appreciate it.

    thanks
    Please use code tags. See reply guidelines. You can display the calculation to 3 decimal places using string formatting.[code=Python]print "Poured into keg and shared: %0.3f beer per person" % (y/float(x))[/code]

    Comment

    Working...