python temperature convertor between Celsius and Fahrenheit

#it will provide a introduction to the program
print('''Welcome to Temperature Convertor. nYou can convert between 'A. Celsius to Fahrenheit', and 'B. Fahrenhet to Celcius''')
#we're defining a converter function
def convertr():
#capturing the choice
	selectconv = raw_input(''' Press A to convert Celcius to Fahrenheit n Press B to convert Fahrenheit to Celcius ''')
	#if A is selected
	if selectconv ==("A") or selectconv == ("a"):
		#collecting celcius value
		celcius = int(raw_input("please enter temperature to convert from celcius to fahrenheit"))
		#making the calculation
		fahrenheit = 9.0/5.0 * celcius + 32
		#printing the converted value
		print "the converted %f celcius is %f fahrenheit" %(celcius,fahrenheit)

	#if B is selected
	elif selectconv ==("B") or selectconv == ("b"):
		#collecting fahrenheit value
		fahrenheit = int(raw_input("please enter temperature to convert from fahrenheit to celcius"))
		#making the calculation
		celcius = (5.0/9.0) * (fahrenheit - 32)
		#printing the converted value
		print "the converted %f fahrenheit is %f celcius" %(fahrenheit, celcius)
	else:
		#letting the user know if they didnt make proper choice
		print("please make a choice")
convertr()	

#here we are performing the loop to ask if the program need to be executed again
def loop():
	restartprgm = raw_input("Do you want to try again?")
	while restartprgm == ("Yes") or restartprgm == ("yes") or restartprgm == ("YES") or restartprgm == ("Y") or  restartprgm == ("y"):
		return convertr()
	else:
		while restartprgm == ("No") or restartprgm == ("no") or restartprgm == ("NO"):
			print ("see you later")
			exit()
loop()

 

This entry was posted in Python and tagged , . Bookmark the permalink.