473,387 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

New to python, baffled by program output

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.
Jul 18 '05 #1
2 1583
On 30 Sep 2004 12:15:24 -0700, La******@gmail.com (Lazareth S. Link)
wrote:
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
---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.


Jul 18 '05 #2
Fuzzyman <fu******@gmail.com> wrote in message news:<61********************************@4ax.com>. ..
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.
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Ray | last post by:
Hello guys, OK, I've been reading some more about Python. There are some things about Python exception that I haven't been able to grasp: 1. This is a small thing, but why is object spelled...
12
by: adamurbas | last post by:
ya so im pretty much a newb to this whole python thing... its pretty cool but i just started today and im already having trouble. i started to use a tutorial that i found somewhere and i followed...
14
by: Nathan Pinno | last post by:
How do I factor a number? I mean how do I translate x! into proper Python code, so that it will always do the correct math? Thanks in advance, Nathan P.
4
by: Derek Martin | last post by:
Hi kids! I've got some code that uses select.select() to capture all the output of a subprocess (both stdout and stderr, see below). This code works as expected on a variety of Fedora systems...
8
by: joemacbusiness | last post by:
Hi All, How do I format printed data in python? I could not find this in the Python Reference Manual: http://docs.python.org/ref/print.html Nor could I find it in Matloff's great tutorial:...
1
by: anonymous | last post by:
1 Objective to write little programs to help me learn German. See code after numbered comments. //Thanks in advance for any direction or suggestions. tk 2 Want keyboard answer input, for...
13
by: Liang Chen | last post by:
Hope you all had a nice weekend. I have a question that I hope someone can help me out. I want to run a Python program that uses Tkinter for the user interface (GUI). The program allows me to type...
3
by: schwarz | last post by:
As part of some research I am doing a Python Virtual Machine in Java, and the exact semantics of the STORE_NAME bytecode is unclear to be, so I was hoping somebody here could clarify it. The...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.