5 Replies - 1680 Views - Last Post: 21 June 2009 - 12:46 AM Rate Topic: -----

#1 hdr  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 154
  • Joined: 15-December 08

Help with caffeine calculator

Posted 17 June 2009 - 09:49 AM

I'm just making this simple application with python with calculates the lethal amount of caffeinated drinks you can consume according to your
body weight in kilograms.

The code works fine, it's just when it prints out the result in the console, it simply shows the lethal amount of drinks you can take in one go.

I wanted it to be something like this:

print "Your lethal dose is" + limit + "cans"

The problem is that if I do that, python will produce this error:
print "Your lethal dose is" + limit + "cans"
TypeError: cannot concatenate 'str' and 'int' objects



Here's the code for the complete application:
#!/usr/bin/python

while 1:
	calc=(input("""1)Coke
2)Jolt Cola
3)Red Bull
4)Mountain Dew
5)Exit

Pick Your Poison: """))
	out=""
	if calc==1:
		weight=input("Enter your body weight in kg")
		limit = 150 * weight / 34
		print limit
		break
	elif calc==2:
		weight=input("Enter your body weight in kg")
		limit = 150 * weight / 280
		print limit
		break
	elif calc==3:
		weight=input("Enter your body weight in kg")
		limit = 150 * weight / 80
		print limit
		break
	elif calc==4:
		weight=input("Enter your body weight in kg")
		limit = 150 * weight / 54.5
		print limit
		break
	elif calc==5:
		print 'Exit'
		break
	else:
		print 'Enter only a number from 1 - 5:'
		print



Is This A Good Question/Topic? 0
  • +

Replies To: Help with caffeine calculator

#2 atik97  Icon User is offline

  • ???
  • member icon

Reputation: 144
  • View blog
  • Posts: 715
  • Joined: 16-September 08

Re: Help with caffeine calculator

Posted 17 June 2009 - 10:35 AM

Instead of the line-
print "Your lethal dose is" + limit + "cans"


You can just try this line -
print "Your lethal dose is %s cans"%limit


Was This Post Helpful? 0
  • +
  • -

#3 hdr  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 154
  • Joined: 15-December 08

Re: Help with caffeine calculator

Posted 18 June 2009 - 01:50 AM

oh. I didn't know that. Thanks man. Can I add this one to the DIC code bank?

This post has been edited by hdr: 18 June 2009 - 01:52 AM

Was This Post Helpful? 0
  • +
  • -

#4 atik97  Icon User is offline

  • ???
  • member icon

Reputation: 144
  • View blog
  • Posts: 715
  • Joined: 16-September 08

Re: Help with caffeine calculator

Posted 18 June 2009 - 10:52 AM

You can try submitting the code and the moderator will review your code before accepting it. You can take a look at the below guidelines for submitting snippets-

Quote

Snippet Guidelines
A Code Snippet is a useful piece of code which accomplishes a common task, demonstrates a technique or concept, fills a gap in an existing language, and could be reused in an existing application. Snippets should be well commented and explain the concepts being used. Snippets should be useful to a wide audience. Snippets should conform to standards when possible.

Snippets should not simply be an example of a built in function or library. Snippets should not be full applications unless the application demonstrates a useful concept. Snippets should not be malicious or violate any laws (including intellectual property laws).

Snippets are reviewed individually and may take several days to be approved/disapproved. Approved snippets are worth 25 kudos.

Was This Post Helpful? 0
  • +
  • -

#5 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1003
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: Help with caffeine calculator

Posted 18 June 2009 - 11:37 AM

According to your calculations, my letal amount of cans of Mountain Dew is 189? Is that right?? Sweet.

I know it's off topic but unless my calculator's broken your calcs may be wrong?
Was This Post Helpful? 0
  • +
  • -

#6 hdr  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 154
  • Joined: 15-December 08

Re: Help with caffeine calculator

Posted 21 June 2009 - 12:46 AM

well, the calculation was given to me by a friend, who then checked and ran the code, and said it's pretty correct.

The caffeine info, well I got them from Wikipedia, which means that it's most likely the US version of those drinks.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1