Converstion Program Equation Help

I cant express the write equation to convert pounts

Page 1 of 1

11 Replies - 1440 Views - Last Post: 30 May 2008 - 09:24 PM Rate Topic: -----

#1 zartek  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 29-May 08

Converstion Program Equation Help

Posted 29 May 2008 - 03:39 AM

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

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



what am i doing wrong
Is This A Good Question/Topic? 0
  • +

Replies To: Converstion Program Equation Help

#2 .Maleficus.  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 129
  • Joined: 07-March 08

Re: Converstion Program Equation Help

Posted 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?
Was This Post Helpful? 0
  • +
  • -

#3 zartek  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 29-May 08

Re: Converstion Program Equation Help

Posted 29 May 2008 - 04:03 AM

View Post.Maleficus., on 29 May, 2008 - 03:55 AM, said:

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
Was This Post Helpful? 0
  • +
  • -

#4 baavgai  Icon User is online

  • Dreaming Coder
  • member icon

Reputation: 4888
  • View blog
  • Posts: 11,284
  • Joined: 16-October 07

Re: Converstion Program Equation Help

Posted 29 May 2008 - 04:54 AM

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

This:
Pound = (1/16);


should probably be this:
Pound = Ounce/16

Was This Post Helpful? 0
  • +
  • -

#5 .Maleficus.  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 129
  • Joined: 07-March 08

Re: Converstion Program Equation Help

Posted 29 May 2008 - 08:37 AM

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 - 08:38 AM

Was This Post Helpful? 0
  • +
  • -

#6 zartek  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 29-May 08

Re: Converstion Program Equation Help

Posted 29 May 2008 - 12:40 PM

View Post.Maleficus., on 29 May, 2008 - 08:37 AM, said:

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
Was This Post Helpful? 0
  • +
  • -

#7 .Maleficus.  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 129
  • Joined: 07-March 08

Re: Converstion Program Equation Help

Posted 29 May 2008 - 02:43 PM

View Postzartek, on 29 May, 2008 - 12:40 PM, said:

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...

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 - 02:46 PM

Was This Post Helpful? 0
  • +
  • -

#8 zartek  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 29-May 08

Re: Converstion Program Equation Help

Posted 29 May 2008 - 02:47 PM

View Post.Maleficus., on 29 May, 2008 - 02:43 PM, said:

View Postzartek, on 29 May, 2008 - 12:40 PM, said:

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...

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?
Was This Post Helpful? 0
  • +
  • -

#9 .Maleficus.  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 129
  • Joined: 07-March 08

Re: Converstion Program Equation Help

Posted 29 May 2008 - 02:58 PM

Sure I guess.
Was This Post Helpful? 0
  • +
  • -

#10 zartek  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 29-May 08

Re: Converstion Program Equation Help

Posted 29 May 2008 - 09:17 PM

View Post.Maleficus., on 29 May, 2008 - 02:58 PM, said:

Sure I guess.


IM going to PM you my aim/yahoo info

View Postzartek, on 29 May, 2008 - 09:16 PM, said:

View Post.Maleficus., on 29 May, 2008 - 02:58 PM, said:

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
Was This Post Helpful? 0
  • +
  • -

#11 .Maleficus.  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 129
  • Joined: 07-March 08

Re: Converstion Program Equation Help

Posted 30 May 2008 - 03:37 AM

I'm pretty sure you need 10 posts to send/receive PMs. Gotta post a little more first :).
Was This Post Helpful? 0
  • +
  • -

#12 zartek  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 29-May 08

Re: Converstion Program Equation Help

Posted 30 May 2008 - 09:24 PM

View Post.Maleficus., on 30 May, 2008 - 03:37 AM, said:

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

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
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1