Connecting Tech Pros Worldwide Help | Site Map

Question regarding int

 
LinkBack Thread Tools Search this Thread
  #1  
Old October 7th, 2008, 03:25 PM
Newbie
 
Join Date: Oct 2008
Posts: 3
Default 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
Reply
  #2  
Old October 7th, 2008, 03:39 PM
bvdet's Avatar
Moderator
 
Join Date: Oct 2006
Location: Nashville, TN
Posts: 1,439
Default

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
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search


Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.