-5

Working on a program for class. I have the following code, however, even though the code works fine; I have a formatting issue.

This here is the correct output that I am trying to get

This is what I currently have; and is wrong

Below is the current code I have:

num_rods = input ( "Input rods: You input " )
num_rods = float ( num_rods )
print ("rods.")

What is the error here? and how can I make my code look like the example; thanks.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Richard
  • 23
  • 6
  • 2
    You don't print your variable. You just print the string `"rods."` – khelwood Sep 10 '18 at 13:28
  • I don't think that first image actually shows the entered value because you're required to press enter, which makes a line break. According to what do you need to use `input()` function? – OneCricketeer Sep 10 '18 at 13:32
  • Also, you're already printing `1.0 rods` at the end, so the title of the question is misleading – OneCricketeer Sep 10 '18 at 13:32
  • The first one if the "right answer", the next one is what I personally got – Richard Sep 10 '18 at 13:34
  • I think we all understand that... But the "code you currently have" never prints "Conversions", so what's in the question is not a [mcve] – OneCricketeer Sep 10 '18 at 13:35
  • Haven't you found this in your research? https://docs.python.org/3.4/library/string.html#format-string-syntax It's hard to believe ... or this: https://www.python.org/dev/peps/pep-3101/ – colidyre Sep 10 '18 at 13:39

2 Answers2

0

Try

print('{} rods.'.format(num_rods))

or

print('rods: ',num_rods)

Also, be careful with statements of this type. Check what happens to the code if, instead of inputting an int or float, you pass the character 'a' for example.

Daneel R.
  • 527
  • 3
  • 9
0

You're seeing a line break, which cannot be avoided

Possible to get user input without inserting a new line?

But you can work around it

entered = input ( "Input rods: You input " )  # literally type "1.0 rods."
amount, _ = entered.split()
... 
print ("Minutes to walk {:.1f} rods:".format(amount))  # but you're already printing this
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245