# Help with caffeine calculator

Page 1 of 1

## 5 Replies - 2351 Views - Last Post: 21 June 2009 - 12:46 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=110525&amp;s=b1560119a4f341aa69da158a59d2aebe&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 hdr

Reputation: 5
• Posts: 155
• 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

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

• ???

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

## Re: Help with caffeine calculator

Posted 17 June 2009 - 10:35 AM

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

```

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

```

### #3 hdr

Reputation: 5
• Posts: 155
• 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

### #4 atik97

• ???

Reputation: 144
• 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.

### #5 RudiVisser

• .. does not guess solutions

Reputation: 1010
• Posts: 3,566
• 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?

### #6 hdr

Reputation: 5
• Posts: 155
• 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.