Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 python help, Unit Conversion Program
Index -> Programming, Python -> Python Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
burmantanya




PostPosted: 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.
Sponsor
Sponsor
Sponsor
sponsor
Zeroth




PostPosted: 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...
burmantanya




PostPosted: 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?
Zeroth




PostPosted: 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?
burmantanya




PostPosted: 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
Zeroth




PostPosted: 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?
burmantanya




PostPosted: 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..
burmantanya




PostPosted: 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??
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: 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.
burmantanya




PostPosted: 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?
burmantanya




PostPosted: 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!
burmantanya




PostPosted: 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
Zeroth




PostPosted: 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.
Zeroth




PostPosted: 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]
burmantanya




PostPosted: 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!
Display posts from previous:   
   Index -> Programming, Python -> Python Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 16 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: