Connecting Tech Pros Worldwide Help | Site Map

Question regarding int

  #1  
Old October 7th, 2008, 04:25 PM
Newbie
 
Join Date: Oct 2008
Posts: 3
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
  #2  
Old October 7th, 2008, 04:39 PM
bvdet's Avatar
Moderator
 
Join Date: Oct 2006
Location: Nashville, TN
Posts: 1,545

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Question regarding UB Philip Potter answers 5 February 26th, 2008 09:55 PM
Question regarding scope and lifetime of variable somenath answers 5 December 24th, 2007 02:05 PM
Question regarding references. Renji Panicker answers 2 November 8th, 2007 09:25 AM
Question regarding int* const in function call. Andrew Isaverdian answers 2 May 10th, 2006 03:25 PM