New to python, baffled by program output

L

Lazareth S. Link

Hiya to whoever might stumble across this.

I've recently taken up learning how to script/program in python.
I've made my first program, a simple fahrenheit-celsius converter,
both ways.
For some reason I fail to comprehend, the program writes a line of
"None" when rerun in a while loop.
Here is the code:

---START---
def choice_c():
print
celsius = input("Input celsius: ")
print "Fahrenheit: ",cel_fah(celsius)
print

def choice_f():
print
fahrenheit = input("Input fahrenheit: ")
print "Celsius: ",fah_cel(fahrenheit)
print

def cel_fah(placeholder):
return 9.0/5.0*placeholder+32

def fah_cel(placeholder):
return (placeholder-32.0)*5.0/9.0

def options():
print "press 'c' to convert celsius to fahrenheit."
print "press 'f' to convert fahrenheit to celsius."
print "press 'q' to exit program."

choice = "n"
options()
while choice != "q":
choice = raw_input("Choice: ")
if choice == "c":
choice_c()
elif choice == "f":
choice_f()
print options()
---END---

Any of you know why it prints that line? Is is just my comp?
If any applies, how to get around it?
Would greatly appreciate the help.
 
F

Fuzzyman

Hiya to whoever might stumble across this.

I've recently taken up learning how to script/program in python.
I've made my first program, a simple fahrenheit-celsius converter,
both ways.
For some reason I fail to comprehend, the program writes a line of
"None" when rerun in a while loop.
Here is the code:

---START---
def choice_c():
print
celsius = input("Input celsius: ")
print "Fahrenheit: ",cel_fah(celsius)
print

def choice_f():
print
fahrenheit = input("Input fahrenheit: ")
print "Celsius: ",fah_cel(fahrenheit)
print

def cel_fah(placeholder):
return 9.0/5.0*placeholder+32

def fah_cel(placeholder):
return (placeholder-32.0)*5.0/9.0

def options():
print "press 'c' to convert celsius to fahrenheit."
print "press 'f' to convert fahrenheit to celsius."
print "press 'q' to exit program."

choice = "n"
options()
while choice != "q":
choice = raw_input("Choice: ")
if choice == "c":
choice_c()
elif choice == "f":
choice_f()
print options()

This is your problem.
You're telling python to print the resultof the function options()
When called options prints the options - but it doesn't have an
explicit return value. This means that it returns None when it has
finished and python duly prints that for you.

Replace 'print options()' with just 'options()' which will just call
the options procedure without expecting a return value.

HTH

Regards,

Fuzzy
 
L

Lazareth S. Link

Fuzzyman said:
This is your problem.
You're telling python to print the resultof the function options()
When called options prints the options - but it doesn't have an
explicit return value. This means that it returns None when it has
finished and python duly prints that for you.

Replace 'print options()' with just 'options()' which will just call
the options procedure without expecting a return value.

HTH

Regards,

Fuzzy

Doh, soo simple, thanks alot Fuzzy =D
I should be more observant in the future.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top