Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Functions
#5
Hi guys, thanks for the advice. I went to re-wrote the code by defining all the parameters in a single function.

def convertTemp (temp=0, tempConvert="C"):
if tempConvert == "F":
temp = (temp - 32)/1.8
print("Celsius to Fahrenheit: %.2f" % temp,tempConvert)

elif tempConvert == "C":
temp = (temp * 1.8)+32
print("Fahrenheit to Celsius:",temp,tempConvert)

else:
print("Invalid Temperature type")
print("Temperature type must be either F for Fahrenheit or C for Celsius")

return temp

convertTemp(100,"F")
Perfringo, thanks for the assist! Your code is slightly way too high for me to understand. However, appreciate it anyway.
Reply


Messages In This Thread
Functions - by harold - Sep-11-2019, 03:55 AM
RE: Functions - by perfringo - Sep-11-2019, 06:16 AM
RE: Functions - by buran - Sep-11-2019, 06:40 AM
RE: Functions - by perfringo - Sep-11-2019, 06:57 AM
RE: Functions - by harold - Sep-11-2019, 07:06 AM
RE: Functions - by perfringo - Sep-11-2019, 07:43 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020