Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,154,813 members, 7,824,380 topics. Date: Saturday, 11 May 2024 at 09:13 AM

Can Someone Please Help Me With This Python Program? - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Can Someone Please Help Me With This Python Program? (1091 Views)

Help With This Python Algorithm.... / I Need HELP With This Python Problem / Please Help With This Python Code (2) (3) (4)

(1) (Reply) (Go Down)

Can Someone Please Help Me With This Python Program? by nep2ra(m): 10:18pm On Jan 24, 2013
Hi all,

Please I want some help with the python program below. I started learning python programming late last year, December 2012. As an extra credit, I decided to practice my skill in writing functions, so I wrote a program to convert Celsius to Fahrenheit and vice versa. To me, the program looks ok as I have tried my best to fix all errors but this annoying error keeps coming up:

File "farcel.py", line 17
elif value == "2":
SyntaxError: invalid syntax


Here is the program:


print "******************************************************"
print " TEMPERATURE CONVERTER"
print "******************************************************"

def temp_conv():
print "This application converts Celsius to Farenheit and vice versa."
print "1. Press 1 if you want to convert Celsius to Farenheit."
print "2. Press 2 if you want to convert Farenheit to Celsius."

value = raw_input('> ')

if value == "1":
print "Please enter the value in Celsius you want to convert to Farenheit.\n"
cel_temp = raw_input('> ')
far = (1.8 * float(cel_temp)) + 32
print "The value in farenheit is: %r degree farenheit" % str(far)
elif value == "2":
print "Please enter the value in Farenheit you want to convert to Celsius.\n"
far_temp = raw_input('> ')
cel = 0.56 * (float(far_temp) - 32)
print "The value in celsius is: %r degree celsius" % str(cel)
else:
print "Please choose option 1 or 2."



temp_conv()


I appreciate every contribution to help me fix this bug.

Thank you.
Re: Can Someone Please Help Me With This Python Program? by Nobody: 11:32am On Jan 25, 2013
upload a snapshot so we can see ur indents
Re: Can Someone Please Help Me With This Python Program? by nep2ra(m): 6:24pm On Jan 25, 2013
Here it is. Hope you can make do with this





[img][/img]
Re: Can Someone Please Help Me With This Python Program? by nep2ra(m): 6:48pm On Jan 25, 2013
Sorry about that. I'm finding it difficult to upload images on here. I copied the screenshot on Microsoft Word but can't upload it.
Re: Can Someone Please Help Me With This Python Program? by codeaddict(m): 8:26am On Jan 26, 2013
Try uploading the .py script.
Re: Can Someone Please Help Me With This Python Program? by Creatrixity(m): 7:58pm On Jan 26, 2013
Hey man,your syntax is invalid cos elif=="2" is wrong.it is elif variable==2:
#give four spaces then do stuff
Re: Can Someone Please Help Me With This Python Program? by nep2ra(m): 2:25am On Jan 27, 2013
Creatrixity: Hey man,your syntax is invalid cos elif=="2" is wrong.it is elif variable==2:
#give four spaces then do stuff

Hey man, thanks for your contribution.

Ummm...I don't see nothing wrong with that line.
I wrote:
elif value == "2":

'value' being the variable and "2" being the option entered.

I'm frustrated with trying to upload a snapshot of the code. It's a nightmare.
Re: Can Someone Please Help Me With This Python Program? by Nobody: 3:45am On Jan 27, 2013
Hello nep2ra.
I copied your program, gave it the required indentations, and ran it on my linux machine and it worked fine. In fact without a single exception raised. It is likely then that the error you encountered has to do with indentation. I have tried to attach the correctly indented version, but if that doesn't work fine here is an information on the indentation I employed: (I used Tab for indentation):

def temp_conv(): ##No Indentation
print "This application converts Celsius to Farenheit and vice versa." ## A single Tab
print "1. Press 1 if you want to convert Celsius to Farenheit." ## A single Tab
print "2. Press 2 if you want to convert Farenheit to Celsius." ## A single Tab

value = raw_input('> ') ## A single Tab

if value == "1": ## A single Tab
print "Please enter the value in Celsius you want to convert to Farenheit.\n" ## Two Tabs
cel_temp = raw_input('> ') ## Two Tabs
far = (1.8 * float(cel_temp)) + 32 ## Two Tabs
print "The value in farenheit is: %r degree farenheit" % str(far) ## Two Tabs
elif value == "2": ## A single Tab
print "Please enter the value in Farenheit you want to convert to Celsius.\n" ## Two Tabs
far_temp = raw_input('> ') ## Two Tabs
cel = 0.56 * (float(far_temp) - 32) ## Two Tabs
print "The value in celsius is: %r degree celsius" % str(cel) ## Two Tabs
else: ## A single Tab
print "Please choose option 1 or 2." ## Two Tabs

temp_conv() ## No Tab


Have fun Pythrogramming!
jide

Re: Can Someone Please Help Me With This Python Program? by nep2ra(m): 11:43am On Jan 27, 2013
Hi jide,
Thanks for your contribution.
The original program has all the correct indentation. Copying and pasting the code on Nairaland is what makes it look like there's no indentation.
I will try your suggestion.

Thanks once again.

Have a good day.

(1) (Reply)

Developing For China Phone / Urgent Help On E-tutor Design / Do U Use Or Know About Nodejs? Come In Please?

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 21
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.