Output showing "None" in Terminal

dn PythonList at DancesWithMice.info
Tue Aug 25 05:11:06 EDT 2020


On 25/08/2020 01:12, Py Noob wrote:
> Hi!
> 
> i'm new to python and would like some help with something i was working on
> from a tutorial. I'm using VScode with 3.7.0 version on Windows 7. Below is
> my code and the terminal is showing the word "None" everytime I execute my
> code.
> 
> Many thanks!
> 
> print("Conversion")
> 
> def km_mi():
>      return answer
> 
> selection = input("Type mi for miles or km for kilometers: ")
> 
> if selection == "mi":
>      n = int(input(print("Please enter distance in miles: ")))
>      answer = (1.6*n)
>      print("%.2f" % answer, "miles")
> 
> else:
>      n = float(input(print("Please enter distance in kilometers: ")))
>      answer = (n/1.6)
>      print("%.2f" % answer, "kilometers")
> 
> answer = km_mi


Without claiming to speak for @Calvin, I think the original question was 
reasonably clear (albeit incomplete), but the code-answer doesn't seem 
to fit together and thus invites the question about 'intention'.

Here's a question or two: is this a course-assignment? If so, which 
course and is the full question and course-content leading to this point 
available on-line? A bunch of people here could write the code. However, 
that won't help you learn Python!

Let's look at the code and the email text:
- does the term "None" mean that even the "Conversion" heading/intro 
does not appear?
- what is the purpose of the function?
- if the two branches of the if statement each print a result, what is 
the purpose of the last line?
- is the specification that the program computes (exactly) one result, 
or is it expected to repeat an input-calculate-output cycle?
- by "terminal" are you referring to the one built-in to VS-Code, or 
something else?

Please be advised that everyone here is volunteering his/her assistance, 
so the more you help us, the better we can help you! Also, are you aware 
that there is a Python-Tutor list specifically for Python trainers and 
trainees?
-- 
Regards =dn


More information about the Python-list mailing list