Problem with python program pls helllllp - Programmers Heaven

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# Problem with python program pls helllllp

Posts: 1Member
[B]Hi..i need help in a program that im trying to write in pyhthon.I have 2 programs made.the first is this:
(The program converts temperatures , so u enter a number for ex. 4 celsius degrees and that is vonverted to 340 kelvin degrees(not correct!) ae a result)

print "Choose what you want to convert.....(type a number from 1 to 6)"
print "1 - Celsius-Kelvin"
print "2 - Celsius-Farenheit"
print "3 - Kelvin-Celsius"
print "4 - Kelvin-Farenheit"
print "5 - Farenheit-Celsius"
print "6 - Farenheit-Kelvin"

deg = input(">: ")

if deg == 1:
celsius1 = input("Type the celsius degrees to convert them to kelvin: ")
kel1 = celsius1+273.15
print "The result is", kel1

if deg == 2:
celsius2 = input("Type the celsius degrees to convert them to farenheit: ")
far1 = celsius2*1.8+32
print "The result is", far1

if deg == 3:
kelvin1 = input("Type the kelvin degrees to convert them to celsius: ")
cel1 = kelvin1-273.15
print "The result is", cel1

if deg == 4:
kelvin2 = input("Type the kelvin degrees to convert them to farenheit: ")
far2 = (kelvin2-273.15)*(9/5)+32
print "The result is", far2

if deg == 5:
farenheit1 = input("Type the farenheit degrees to convert them to celsius: ")
cel2 = (farenheit1-32)/1.8
print "The result is", cel2

if deg == 6:
farenheit2 = input("Type the farenheit degrees to convert them to kelvin: ")
kel2 = (5/9)*(farenheit2-32)+273.15

input("press to quit")

[B]the second makes a textbox around a typed sentence::[/B]

sentence = raw_input("Sentence: ")

screen_width = 80
text_width = len(sentence)
box_width = text_width + 6
left_margin = (screen_width - box_width) // 2

print
print ' ' * left_margin + '+' + '-' * (box_width-2) + '+'
print ' ' * left_margin + '| ' + ' ' * text_width + ' |'
print ' ' * left_margin + '| ' + sentence + ' |'
print ' ' * left_margin + '| ' + ' ' * text_width + ' |'
print ' ' * left_margin + '+' + '-' * (box_width-2) + '+'
print
input('Press to quit')

[B]the problem starts when i try to make these programs into one program and so the result of the first outputs in a textbox but i have a problem with the strings, tuples and so on.Im a begginer and i found these two programs in a tutorial and i dont know how to do this because i havent learned this yet
[/B]

Pls help this is urgent here is msn: boris.kaculacki(AT)hotmail.com for contact . THX very much!

• Posts: 1Member
print

print "Choose what you want to convert.....(type a number from 1 to 6)"
print "1 - Celsius-Kelvin"
print "2 - Celsius-Farenheit"
print "3 - Kelvin-Celsius"
print "4 - Kelvin-Farenheit"
print "5 - Farenheit-Celsius"
print "6 - Farenheit-Kelvin"

deg = input(">: ")

if deg == 1:
celsius1 = input("Type the celsius degrees to convert them to kelvin: ")
kel1 = celsius1+273.15
print "The result is", kel1

if deg == 2:
celsius2 = input("Type the celsius degrees to convert them to farenheit: ")
far1 = celsius2*1.8+32
print "The result is", far1

if deg == 3:
kelvin1 = input("Type the kelvin degrees to convert them to celsius: ")
cel1 = kelvin1-273.15
print "The result is", cel1

if deg == 4:
kelvin2 = input("Type the kelvin degrees to convert them to farenheit: ")
far2 = (kelvin2-273.15)*(9/5)+32
print "The result is", far2

if deg == 5:
farenheit1 = input("Type the farenheit degrees to convert them to celsius: ")
cel2 = (farenheit1-32)/1.8
print "The result is", cel2

if deg == 6:

farenheit2 = input("Type the farenheit degrees to convert them to kelvin: ")
kel2 = (5/9)*(farenheit2-32)+273.15

sentence = raw_input("Sentence: ")

screen_width = 80
text_width = len(sentence)
box_width = text_width + 6
left_margin = (screen_width - box_width) // 2

print
print ' ' * left_margin + '+' + '-' * (box_width-2) + '+'
print ' ' * left_margin + '| ' + ' ' * text_width + ' |'
print ' ' * left_margin + '| ' + sentence + ' |'
print ' ' * left_margin + '| ' + ' ' * text_width + ' |'
print ' ' * left_margin + '+' + '-' * (box_width-2) + '+'
• Posts: 1Member
This seems a much more elegant solution to me:
[code]
def convert(deg):
if deg == "1":
celsius1 = input("Type the celsius degrees to convert them to kelvin: ")
kel1 = celsius1+273.15
return kel1

if deg == "2":
celsius2 = input("Type the celsius degrees to convert them to farenheit: ")
far1 = celsius2*1.8+32
return far1

if deg == "3":
kelvin1 = input("Type the kelvin degrees to convert them to celsius: ")
cel1 = kelvin1-273.15
return cel1

if deg == "4":
kelvin2 = input("Type the kelvin degrees to convert them to farenheit: ")
far2 = (kelvin2-273.15)*(9/5)+32
return far2

if deg == "5":
farenheit1 = input("Type the farenheit degrees to convert them to celsius: ")
cel2 = (farenheit1-32)/1.8
return cel2

if deg == "6":
farenheit2 = input("Type the farenheit degrees to convert them to kelvin: ")
kel2 = (5/9)*(farenheit2-32)+273.15
return kel2

def sentence(convert):
sentence = convert
screen_width = 80
text_width = len(str(sentence))
box_width = text_width + 6
left_margin = (screen_width - box_width) // 2

print
print ' ' * left_margin + '+' + '-' * (box_width-4) + '+'
print ' ' * left_margin + '| ' + ' ' * text_width + ' |'
print ' ' * left_margin + '| ' + str(sentence) + ' |'
print ' ' * left_margin + '| ' + ' ' * text_width + ' |'
print ' ' * left_margin + '+' + '-' * (box_width-4) + '+'

def main():
print "Choose what you want to convert.....(type a number from 1 to 6)"
print "1 - Celsius-Kelvin"
print "2 - Celsius-Farenheit"
print "3 - Kelvin-Celsius"
print "4 - Kelvin-Farenheit"
print "5 - Farenheit-Celsius"
print "6 - Farenheit-Kelvin"

deg = raw_input(">: ")
print sentence(convert(deg))

if __name__ == "__main__":
main()[/code]