1
Python, hjälp
Postat av smajLLL den 17 Februari 2011, 15:42
5 kommentarer · 261 träffar
Hej, skulel behöva lite hjälp med en läxa lite snabbt, kopierar in koden här, det finns ngra fel i den, men fattar inte vad...
#!usr/bin/python
# -*- coding: utf-8 -*-
def tillFahrenheit(celsius):
fahre nheit = (celsius * 9 / 5.0) + 32
ret = str(celsius) + "C = "
ret = ret + str(int(round(celsius))) + "F "
return ret
def tillCelsius(fahrenheit):
celsi us = (fahrenheit - 32) * 5.0 / 9
ret = str(fahrenheit) + "F = "
ret = ret + str(int(round(celsius))) + "C "
return ret
def rensaIn(txt):
return int(txt[:-1])
def konv():
print "-"*50
print "temperaturkonverterare"
print "syntax: 30C, 20F, -10C, etc, avsluta med q"
while True:
txt = raw_input("? ")
if txt.lower() == "q":
break
typ = txt[-1]
if typ == "C":
print tillFahrenheit(rensaIn(txt))
e lif typ == "F":
print tillCelsius(rensaIn(txt))
else :
print "Okänd syntax"
konv()
#!usr/bin/python
# -*- coding: utf-8 -*-
def tillFahrenheit(celsius):
fahre nheit = (celsius * 9 / 5.0) + 32
ret = str(celsius) + "C = "
ret = ret + str(int(round(celsius))) + "F "
return ret
def tillCelsius(fahrenheit):
celsi us = (fahrenheit - 32) * 5.0 / 9
ret = str(fahrenheit) + "F = "
ret = ret + str(int(round(celsius))) + "C "
return ret
def rensaIn(txt):
return int(txt[:-1])
def konv():
print "-"*50
print "temperaturkonverterare"
print "syntax: 30C, 20F, -10C, etc, avsluta med q"
while True:
txt = raw_input("? ")
if txt.lower() == "q":
break
typ = txt[-1]
if typ == "C":
print tillFahrenheit(rensaIn(txt))
e lif typ == "F":
print tillCelsius(rensaIn(txt))
else :
print "Okänd syntax"
konv()






