Connecting Tech Pros Worldwide Forums | Help | Site Map

Question regarding int

Newbie
 
Join Date: Oct 2008
Posts: 3
#1: Oct 7 '08
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's Avatar
Moderator
 
Join Date: Oct 2006
Location: Nashville, TN
Posts: 1,563
#2: Oct 7 '08

re: Question regarding int


Quote:

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.
Expand|Select|Wrap|Line Numbers
  1. print "Poured into keg and shared: %0.3f beer per person" % (y/float(x))
Reply