School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,444 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,524 people online right now. Registration is fast and FREE... Join Now!




Help with caffeine calculator

 

Help with caffeine calculator

hdr

17 Jun, 2009 - 08:49 AM
Post #1

New D.I.C Head
Group Icon

Joined: 15 Dec, 2008
Posts: 27


Dream Kudos: 25
My Contributions
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:
CODE

print "Your lethal dose is" + limit + "cans"
TypeError: cannot concatenate 'str' and 'int' objects


Here's the code for the complete application:
CODE

#!/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


User is offlineProfile CardPM
+Quote Post


shadhin

RE: Help With Caffeine Calculator

17 Jun, 2009 - 09:35 AM
Post #2

D.I.C Regular
Group Icon

Joined: 16 Sep, 2008
Posts: 421



Thanked: 19 times
Dream Kudos: 3650
My Contributions
Instead of the line-
CODE

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

You can just try this line -
CODE

print "Your lethal dose is %s cans"%limit

User is offlineProfile CardPM
+Quote Post

hdr

RE: Help With Caffeine Calculator

18 Jun, 2009 - 12:50 AM
Post #3

New D.I.C Head
Group Icon

Joined: 15 Dec, 2008
Posts: 27


Dream Kudos: 25
My Contributions
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 Jun, 2009 - 12:52 AM
User is offlineProfile CardPM
+Quote Post

shadhin

RE: Help With Caffeine Calculator

18 Jun, 2009 - 09:52 AM
Post #4

D.I.C Regular
Group Icon

Joined: 16 Sep, 2008
Posts: 421



Thanked: 19 times
Dream Kudos: 3650
My Contributions
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.

User is offlineProfile CardPM
+Quote Post

RudiVisser

RE: Help With Caffeine Calculator

18 Jun, 2009 - 10:37 AM
Post #5

.. does not guess solutions
Group Icon

Joined: 5 Jun, 2009
Posts: 1,872



Thanked: 137 times
Dream Kudos: 125
Expert In: PHP, MySQL, HTML, CSS, C#

My Contributions
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?
User is offlineProfile CardPM
+Quote Post

hdr

RE: Help With Caffeine Calculator

20 Jun, 2009 - 11:46 PM
Post #6

New D.I.C Head
Group Icon

Joined: 15 Dec, 2008
Posts: 27


Dream Kudos: 25
My Contributions
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.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 01:37AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month