Newbie! I'm a newbie! What's wrong with this program?

I'm very new at programing, and while I was practicing I came across
something that confuses me. The code for the program is at the bottom.
The program it self is designed to convert hours to minutes. Now the
problem is, after I run the program I get strange results.

[\| Running the Program |/]

INPUT:
Ms-Dos Prompt:
C:\python23\> python practice.py

OUTPUT:

There are 300
None minutes in 5 hours <--- Problem occurs here

[\|End Running of Program|/]

Now the problem is... where does the "None" come from? And why is it
there? Here is the code. Please email me if you can. Your help is
appreciated.

Here you're trying to print the return value of minHour, which since you
didn't return anything, defaults to None. Fix it by making that last
line of minHour

return hour

instead of

print hour
> newLine();
> print "Program Terminated.";
> newLine();

Note that Python does not require an end of line discriminator, so all
these semicolons are redundant (you seem to know this since since you
don't use them in some places, but use them in others). (Also,
"newLine()" really is a curious abbreviation for "print" .

(Id0x) wrote in message news:<>...
> There are 300
> None minutes in 5 hours <--- Problem occurs here
>
> [\|End Running of Program|/]
>
> Now the problem is... where does the "None" come from? And why is it
> there? Here is the code. Please email me if you can. Your help is
> appreciated.

The "None" comes from:
> def newLine():
> print

What you meant was:
def newLine():
print "\r"
(I must admit that I am not familiar with line endings on windoze, in
linux it is "\n", on windoze it might be "\r" or "\r\n", I don't know
for sure, however you don't need this function at all)

No, that isn't where it comes from.
> (I must admit that I am not familiar with line endings on windoze, in
> linux it is "\n", on windoze it might be "\r" or "\r\n", I don't know
> for sure, however you don't need this function at all)

If sys.stdout is opened in text mode then '\n' will get translated to
the appropriate form regardless. So this is a red herring you're after.
> You might try something like:
>
> print "There are " + str(minHour(x_hours)) + " minutes in " +
> str(x_hours) + " hours"

That would still print exactly the same thing. The problem is that
minHour is returning None (implicitly).

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!