Skip to content

Instantly share code, notes, and snippets.

@HiroNakamura
Created October 28, 2023 19:27
Show Gist options
  • Save HiroNakamura/bf36f31bc9b9fbd9b9a1ae4bae1167ec to your computer and use it in GitHub Desktop.
Save HiroNakamura/bf36f31bc9b9fbd9b9a1ae4bae1167ec to your computer and use it in GitHub Desktop.
Katas of Programming
#!/bin/python
# coding=utf-8
import os
from math import ceil
def celsius(value):
return ceil((value - 32)*(5/9))
def fahrenheit(value):
return ceil((value* 9/5) + 32)
def main():
os.system('clear')
print("\t [ Calculates the conversion from degrees Celsius to Fahrenheit and viceversa ]")
try:
grade = float(input("Enter a grade: "))
option = int(input("\t *** Menu *** \n\t1. Celsius to Fahrenheit.\n\t2. Fahrenheit to Celsius.\n\tYour option is:"))
except ValueError as ex:
print(f"ValueError: {ex}")
print(f"{grade} or {option} are not numeric.\n Please, enter a numeric value.")
if option == 1:
print(f"Celsius to Fahrenheit is: {fahrenheit(grade)}")
elif option == 2:
print(f"Fahrenheit to Celsius is: {celsius(grade)}")
else:
print(f"The option ({option}) is not correct.")
print("Done!")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment