Welcome to Dream.In.Code
Getting Help is Easy!

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




Converstion Program Equation Help

 
Reply to this topicStart new topic

Converstion Program Equation Help, I cant express the write equation to convert pounts

zartek
post 29 May, 2008 - 02:39 AM
Post #1


New D.I.C Head

*
Joined: 29 May, 2008
Posts: 19


My Contributions


This is the first program i have ever written and im having problems with the conversion equation for Ounces to Pounds
here is my code plz help

CODE

def Greydon():
    Ounce       = input ('Weight in Ounces:');
    Pound       = (1/16);
    print Ounce, 'Ounce =', Pound, 'Pound';
    


what am i doing wrong
User is offlineProfile CardPM

Go to the top of the page

.Maleficus.
post 29 May, 2008 - 02:55 AM
Post #2


D.I.C Head

**
Joined: 7 Mar, 2008
Posts: 126



Thanked 2 times
My Contributions


Are you trying to do the actual math and convert ounces to pounds or just print "Ounces = (1/16) Pound"?

Also, what errors are you getting?
User is offlineProfile CardPM

Go to the top of the page

zartek
post 29 May, 2008 - 03:03 AM
Post #3


New D.I.C Head

*
Joined: 29 May, 2008
Posts: 19


My Contributions


QUOTE(.Maleficus. @ 29 May, 2008 - 03:55 AM) *

Are you trying to do the actual math and convert ounces to pounds or just print "Ounces = (1/16) Pound"?

Also, what errors are you getting?


Well im trying to get the actual conversion equation to be right
oh and no errors just wrong answers
Thanks man for all your help, so hard getting help on forums these days...

Z
User is offlineProfile CardPM

Go to the top of the page

baavgai
post 29 May, 2008 - 03:54 AM
Post #4


Dreaming Coder

Group Icon
Joined: 16 Oct, 2007
Posts: 1,967



Thanked 96 times

Dream Kudos: 475

Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua

My Contributions


You forgot to apply your conversion to your value. Also, python hates semicolons.

This:
CODE
Pound = (1/16);


should probably be this:
CODE
Pound = Ounce/16

User is online!Profile CardPM

Go to the top of the page

.Maleficus.
post 29 May, 2008 - 07:37 AM
Post #5


D.I.C Head

**
Joined: 7 Mar, 2008
Posts: 126



Thanked 2 times
My Contributions


python
def greydon():
ounces = input('Weight in Ounces: ')
pound = str(ounces/16)
print 'Weight is %s lbs' % pound


IIRC Python convention is mostly lowercase with underscores.

This post has been edited by .Maleficus.: 29 May, 2008 - 07:38 AM
User is offlineProfile CardPM

Go to the top of the page

zartek
post 29 May, 2008 - 11:40 AM
Post #6


New D.I.C Head

*
Joined: 29 May, 2008
Posts: 19


My Contributions


QUOTE(.Maleficus. @ 29 May, 2008 - 08:37 AM) *

python
def greydon():
ounces = input('Weight in Ounces: ')
pound = str(ounces/16)
print 'Weight is %s lbs' % pound


IIRC Python convention is mostly lowercase with underscores.


the last line of code 'print...'
did not work, though the other conversion equation ounce/16 works just find, can you explain the last line of code to me?

Thanks again

Z

User is offlineProfile CardPM

Go to the top of the page

.Maleficus.
post 29 May, 2008 - 01:43 PM
Post #7


D.I.C Head

**
Joined: 7 Mar, 2008
Posts: 126



Thanked 2 times
My Contributions


QUOTE(zartek @ 29 May, 2008 - 12:40 PM) *

the last line of code 'print...'
did not work, though the other conversion equation ounce/16 works just find, can you explain the last line of code to me?

Thanks again

Z

It didn't work? That's strange, it worked in the Try Python online interpreter... (I was at school and couldn't test on a PC with actual Python)

...

Testing my code at home now. The last line is working for me, however pounds = str(ounces/16) isn't. %s is just another way of printing a string variable instead of doing print 'Weight is ", pounds, ' lbs'. It says, "Take %s and fill in the variable _____ for that placeholder", with the variable being the one after the % at the end. It works with multiple variables too. For example...

python
var_1 = 'Hello'
var_2 = 'my'
print '%s World, %s name is Andy' % (var_1, var_2)

would print "Hello World, my name is Andy".

Sorry I can't help with that line though, as it works for me. What version of Python are you using?

This post has been edited by .Maleficus.: 29 May, 2008 - 01:46 PM
User is offlineProfile CardPM

Go to the top of the page

zartek
post 29 May, 2008 - 01:47 PM
Post #8


New D.I.C Head

*
Joined: 29 May, 2008
Posts: 19


My Contributions


QUOTE(.Maleficus. @ 29 May, 2008 - 02:43 PM) *

QUOTE(zartek @ 29 May, 2008 - 12:40 PM) *

the last line of code 'print...'
did not work, though the other conversion equation ounce/16 works just find, can you explain the last line of code to me?

Thanks again

Z

It didn't work? That's strange, it worked in the Try Python online interpreter... (I was at school and couldn't test on a PC with actual Python)

...

Testing my code at home now. The last line is working for me, however pounds = str(ounces/16) isn't. %s is just another way of printing a string variable instead of doing print 'Weight is ", pounds, ' lbs'. It says, "Take %s and fill in the variable _____ for that placeholder", with the variable being the one after the % at the end. It works with multiple variables too. For example...

python
var_1 = 'Hello'
var_2 = 'my'
print '%s World, %s name is Andy' % (var_1, var_2)

would print "Hello World, my name is Andy".

Sorry I can't help with that line though, as it works for me. What version of Python are you using?


actually you can, as you've been a huge help already, can you chat?

User is offlineProfile CardPM

Go to the top of the page

.Maleficus.
post 29 May, 2008 - 01:58 PM
Post #9


D.I.C Head

**
Joined: 7 Mar, 2008
Posts: 126



Thanked 2 times
My Contributions


Sure I guess.
User is offlineProfile CardPM

Go to the top of the page

zartek
post 29 May, 2008 - 08:17 PM
Post #10


New D.I.C Head

*
Joined: 29 May, 2008
Posts: 19


My Contributions


QUOTE(.Maleficus. @ 29 May, 2008 - 02:58 PM) *

Sure I guess.


IM going to PM you my aim/yahoo info

QUOTE(zartek @ 29 May, 2008 - 09:16 PM) *

QUOTE(.Maleficus. @ 29 May, 2008 - 02:58 PM) *

Sure I guess.


IM going to PM you my aim/yahoo info


actually why dont you send me yours mine is telling me i cant
User is offlineProfile CardPM

Go to the top of the page

.Maleficus.
post 30 May, 2008 - 02:37 AM
Post #11


D.I.C Head

**
Joined: 7 Mar, 2008
Posts: 126



Thanked 2 times
My Contributions


I'm pretty sure you need 10 posts to send/receive PMs. Gotta post a little more first smile.gif.
User is offlineProfile CardPM

Go to the top of the page

zartek
post 30 May, 2008 - 08:24 PM
Post #12


New D.I.C Head

*
Joined: 29 May, 2008
Posts: 19


My Contributions


QUOTE(.Maleficus. @ 30 May, 2008 - 03:37 AM) *

I'm pretty sure you need 10 posts to send/receive PMs. Gotta post a little more first smile.gif.

oh ok cool thanks man, this site is really dope. i have so many ideas for programs and im anxious to learn alot, i want to work in Xcode eventually. Make apps for the iphone and stuff

User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 07:28AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month