4 Replies - 2929 Views - Last Post: 22 March 2011 - 03:13 PM Rate Topic: -----

#1 almightybob  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 20
  • Joined: 22-March 11

Having a problem with an inches to centimeters conversion table.

Posted 22 March 2011 - 02:27 PM

Hey guys,

I'm having a hard time wrapping my head around in which direction I need my code to go in.
Basically, I need to use a loop (nested or not that's OK) to display to the user an inches
to centimeters conversion table. However, it's the user input I'm having trouble with.
I need this program to prompt the user where they want to start the conversion in inches,
and where they want to end the conversion in inches.

Here's what I got so far:
startconversion = input("Start conversion at (in): ")
stopconversion = input("Finish conversion at (in): ")
for startconversion in range(startconversion,stopconversion,6):
    print str(startconversion) +" inches", "is " + str(stopconversion*2.45) +" centimeters"



I don't know what to do to have this displayed correctly to the user. How it's running now is,
it only converts the stopconversion variable to centimeters, where I need it to convert
all the inches from startconversion to stopconversion .

That's my only problem right now. Sorry if i ran around in circles trying to describe it.
Thanks.

Is This A Good Question/Topic? 1
  • +

Replies To: Having a problem with an inches to centimeters conversion table.

#2 Simown  Icon User is offline

  • Blue Sprat
  • member icon

Reputation: 319
  • View blog
  • Posts: 650
  • Joined: 20-May 10

Re: Having a problem with an inches to centimeters conversion table.

Posted 22 March 2011 - 02:52 PM

Hi almightybob,

The problem you have is you are using a user entered variable in the output:

print str(startconversion) +" inches", "is " + str(stopconversion*2.45) +" centimeters"


If I enter 100 for stopconversion what is stopconversion*2.45? 245, every time!

Next, the value in the output wants to be a variable and not one of the constant names used for user input.

I will call it value but you can call it any name that makes sense to you:

startconversion = int(raw_input("Start conversion at (in): "))
stopconversion = int(raw_input("Finish conversion at (in): "))
for value in range(startconversion,stopconversion,6):
    print str(value) +" inches", "is " + str(value*2.45) +" centimeters"



Output:

Start conversion at in: 1
Finish conversion at (in): 100
1 inches is 2.45 centimeters
7 inches is 17.15 centimeters
13 inches is 31.85 centimeters
19 inches is 46.55 centimeters
25 inches is 61.25 centimeters
31 inches is 75.95 centimeters
37 inches is 90.65 centimeters
43 inches is 105.35 centimeters
49 inches is 120.05 centimeters
55 inches is 134.75 centimeters
61 inches is 149.45 centimeters
67 inches is 164.15 centimeters
73 inches is 178.85 centimeters
79 inches is 193.55 centimeters
85 inches is 208.25 centimeters
91 inches is 222.95 centimeters
97 inches is 237.65 centimeters

Hopefully it's a lot clearer now. Hope that helps :)

This post has been edited by Simown: 22 March 2011 - 03:21 PM

Was This Post Helpful? 2
  • +
  • -

#3 almightybob  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 20
  • Joined: 22-March 11

Re: Having a problem with an inches to centimeters conversion table.

Posted 22 March 2011 - 02:59 PM

Simown,

Thank you so much! This does clear everything up for me.
Thank you for your response. Now I can move forward on my code.
I guess next time I should study the structure of the loop I plan to use.
You should have seen my face when it all clicked with me :bigsmile:

This post has been edited by JackOfAllTrades: 22 March 2011 - 03:47 PM
Reason for edit:: Removed unnecessary quote

Was This Post Helpful? 0
  • +
  • -

#4 Simown  Icon User is offline

  • Blue Sprat
  • member icon

Reputation: 319
  • View blog
  • Posts: 650
  • Joined: 20-May 10

Re: Having a problem with an inches to centimeters conversion table.

Posted 22 March 2011 - 03:10 PM

I wish I could see it, that's great! :D

P.S. You don't really need to quote the post directly above yours. It can get messy! :P
Was This Post Helpful? 0
  • +
  • -

#5 almightybob  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 20
  • Joined: 22-March 11

Re: Having a problem with an inches to centimeters conversion table.

Posted 22 March 2011 - 03:13 PM

Thanks for the tip!
:stuart:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1