Computer Science Canada

python help, Unit Conversion Program

Author:  burmantanya [ Sun Sep 28, 2008 6:32 pm ]
Post subject:  python help, Unit Conversion Program

Hey Y'all
i m a new to python programming. I have never done programming ever in my life.. currently, i m working on this assignment where i have to do the following

- a program in a file that allows a user to convert between the following units of measurement for area: acre, square metre (m2), hectare, and square yard (y2).

allowed to only use raw_input to prompt the user to enter the following:
* the original unit (one of: acre, sqm, hect, sqyd)
* the numeric value to be converted
* the new unit (one of: acre, sqm, hect, sqyd)
print the new value in the form: orig_value orig_unit = new_value new_unit. Calculate new_value by calling the convert function described below.

Original unit: acre
Value to convert: 2.5
New unit: sqyd
2.5 acre = 12101.8421053 sqyd

The answer has to be a float value! please guide me thru the process.

Author:  Zeroth [ Sun Sep 28, 2008 7:03 pm ]
Post subject:  Re: python help, Unit Conversion Program

Our first rule is we won't do your work for you. However, we can provide hints and guidance.

As the resident Python Guru(tm), I can give you some tips, and things to look at. Are you aware of the float and int functions? They also happen to take in strings...

Author:  burmantanya [ Sun Sep 28, 2008 7:32 pm ]
Post subject:  RE:python help, Unit Conversion Program

just with the basics..learned recently..
float would be decimals functions and int - integers.
how do i combine a string and int together? which function and how to use the formula? do i have to make it or is there a shortcut?

Author:  Zeroth [ Sun Sep 28, 2008 7:36 pm ]
Post subject:  Re: python help, Unit Conversion Program

There is also the str function, turns whatever you put into it into a string.

Do you have an idea what you have to do to do this assignment? Like, order of steps, operations needed?

Author:  burmantanya [ Sun Sep 28, 2008 7:39 pm ]
Post subject:  RE:python help, Unit Conversion Program

well..
i have to get the user to input the value..
but the problem is that the value would be integer. the function raw_input is only for strings if i am not wrong

Author:  Zeroth [ Sun Sep 28, 2008 7:43 pm ]
Post subject:  Re: python help, Unit Conversion Program

Yes. It does take in strings. Now, if only you knew of functions that could convert a string to a number... if only...

What else needs to be done?

Author:  burmantanya [ Sun Sep 28, 2008 7:47 pm ]
Post subject:  RE:python help, Unit Conversion Program

the program then has to convert the number (square m) to hectare..

Author:  burmantanya [ Sun Sep 28, 2008 7:48 pm ]
Post subject:  RE:python help, Unit Conversion Program

strings to a number?
would it be still part of the raw input statement??

Author:  wtd [ Sun Sep 28, 2008 8:17 pm ]
Post subject:  Re: RE:python help, Unit Conversion Program

burmantanya @ Mon Sep 29, 2008 8:48 am wrote:
strings to a number?


Zeroth has already answered your question.

Author:  burmantanya [ Sun Sep 28, 2008 9:09 pm ]
Post subject:  RE:python help, Unit Conversion Program

he did..where???
omgg..i m srry..this assignement is killing me..there are no course books or anythin.. our prof just teaches us in class..and thats it..went thru all my notes..seriously..i don't no what 2 do?

Author:  burmantanya [ Sun Sep 28, 2008 9:11 pm ]
Post subject:  RE:python help, Unit Conversion Program

well..thanx Zeroth for taking your time to go thru the assignemnt..i really appreciate it!

Author:  burmantanya [ Sun Sep 28, 2008 9:47 pm ]
Post subject:  RE:python help, Unit Conversion Program

what does the statement looks like thou???
i have been researching on interent like crazziiee

Author:  Zeroth [ Sun Sep 28, 2008 9:50 pm ]
Post subject:  Re: python help, Unit Conversion Program

I'm glad you're figuring it out. If I may recommend this free book: http://diveintopython.org/

Some pro-tips:
Programming is a mentally difficult task. It relies heavily on the brain's ability to re-use what you know in new ways. In essence, programming is creativity. However, it is creativity constrained by logic. What that means is you need access to higher level logic centers, as well as the creative centers of your brain. No drugs, no alcohol, remain calm, and you'll find programming easier. If you get upset, walk it off. Pounding at your keyboard frustratedly will not solve your problems.

Experiment. Try. Learn. Mistakes are not obstacles, merely something new to learn from. Never make the same mistake twice.

If you are confused as to what you need to do, grab a pencil, and a piece of paper. Write down the steps you would need to do to solve the problem. Then think about how to tell the computer to do that.

Author:  Zeroth [ Sun Sep 28, 2008 9:54 pm ]
Post subject:  Re: python help, Unit Conversion Program

Okay, look at this quote:
Quote:
Are you aware of the float and int functions? They also happen to take in strings...


Now, next step. Fire up your python interpreter. Type this in:
code:

int(10.0)
int("10")
float("10")
float(100)
str(10)
str(100+20)


Look at whats happening, what the results are. Think.

Now, after you have been thinking about this, do this,

code:

print str(10)+" is the result."
str(10)+" is the result."
"The answer is: "+str(10)


Now, think again about what you see here. Do not just copy it and muddle through the code. Understand. Learn. [/quote]

Author:  burmantanya [ Sun Sep 28, 2008 10:27 pm ]
Post subject:  RE:python help, Unit Conversion Program

thank you
i feel much better now..
let me try it and see if it wrks..
once again..thanx a ton!

Author:  btiffin [ Sun Sep 28, 2008 10:39 pm ]
Post subject:  Re: RE:python help, Unit Conversion Program

burmantanya @ Sun Sep 28, 2008 9:47 pm wrote:
what does the statement looks like thou???
i have been researching on interent like crazziiee

burmantanya; If you hang out here long enough, you may find I ditto Zeroth from time to time. Had I not refreshed the screen before this post, I wouldn't have even known this time.

To quote Douglas Adams "Don't Panic". As Zeroth just stated. Slow down. wtd gave you a great hint about Zeroth already answering part of the problem. Don't do it in a rush, but read the first reply Zeroth made. Then read it again until you see that he gave you the names of some functions.

And, being a student board, there is actually less direct help here than you may find on more generic technical sites. compsci.ca can make you a better programmer. Hey, may even make you a better person. But it is unlikely that you will find cut and pasteable solutions to class related problems.

And if you really really do get stuck, slow down once again. And even if it is utter disgust and exhaustion, use the power of the Python.
code:
>>> help()
help>

And at that help prompt, type in every word from that first reply Zeroth posted. Eventually the critical keywords will become apparent. By the way, the q key will get you out of any help entries. At least here on my Debian GNU/Linux system.

Best of skill. And some advice from the old guy ... the more pissed off you get, the better it will feel when you get the answer (although you may not notice just how much better until you hit your mid-thirties). Smile

Cheers


: