Skip to content

Instantly share code, notes, and snippets.

@ameeenh
Created January 20, 2023 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ameeenh/9e744011d87ceebe0d276899a8902738 to your computer and use it in GitHub Desktop.
Save ameeenh/9e744011d87ceebe0d276899a8902738 to your computer and use it in GitHub Desktop.
Final Project CyberDefenders
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"authorship_tag": "ABX9TyO7sXhnwuQLl3fcZT4zaK5I",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/ameeenh/9e744011d87ceebe0d276899a8902738/final-project-cyberdefenders.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "oHYpyUl-2OXw",
"outputId": "dbf00218-8520-4b2e-f1cd-e241bb1665d3"
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Please select which a conversion: Roman, Number, CelsiusCelsius\n",
"Enter the temperature: 122\n",
"Enter the unit (Celsius/Fahrenheit): Celsius\n",
"122.0 degrees Celsius is equal to 251.6 degrees Fahrenheit.\n"
]
}
],
"source": [
"def temperature_converter():\n",
" temperature = float(input(\"Enter the temperature: \"))\n",
" unit = input(\"Enter the unit (Celsius/Fahrenheit): \").upper()\n",
" if unit == \"CELSIUS\":\n",
" result = (temperature * 9/5) + 32\n",
" print(f\"{temperature} degrees Celsius is equal to {result} degrees Fahrenheit.\")\n",
" elif unit == \"FAHRENHEIT\":\n",
" result = (temperature - 32) * 5/9\n",
" print(f\"{temperature} degrees Fahrenheit is equal to {result} degrees Celsius.\")\n",
" else:\n",
" print(\"Invalid unit. Please enter either 'Celsius' or 'Fahrenheit'.\")\n",
"\n",
"def convert_to_roman(num):\n",
" roman = \"\"\n",
" roman_numerals = {1000: \"M\", 900: \"CM\", 500: \"D\", 400: \"CD\", 100: \"C\", 90: \"XC\", 50: \"L\", 40: \"XL\", 10: \"X\", 9: \"IX\", 5: \"V\", 4: \"IV\", 1: \"I\"}\n",
" for value in roman_numerals:\n",
" while num >= value:\n",
" roman += roman_numerals[value]\n",
" num -= value\n",
" return roman\n",
"\n",
"def convert_from_roman(roman):\n",
" num = 0\n",
" roman_numerals = {\"M\": 1000, \"CM\": 900, \"D\": 500, \"CD\": 400, \"C\": 100, \"XC\": 90, \"L\": 50, \"XL\": 40, \"X\": 10, \"IX\": 9, \"V\": 5, \"IV\": 4, \"I\": 1}\n",
" i = 0\n",
" while i < len(roman):\n",
" if i+1 < len(roman) and roman_numerals[roman[i]] < roman_numerals[roman[i+1]]:\n",
" num += roman_numerals[roman[i]+roman[i+1]]\n",
" i += 2\n",
" else:\n",
" num += roman_numerals[roman[i]]\n",
" i += 1\n",
" return num\n",
"\n",
"option = input(\"Please select which a conversion: Roman, Number, Celsius\").upper()\n",
"\n",
"if option == \"NUMBER\":\n",
" num = int(input(\"Enter a number: \"))\n",
" result = convert_to_roman(num)\n",
" print(\"The Roman numeral equivalent is:\", result)\n",
"elif option == \"ROMAN\":\n",
" roman = input(\"Enter a Roman numeral: \")\n",
" result = convert_from_roman(roman)\n",
" print(\"The number equivalent is:\", result)\n",
"elif option == \"CELSIUS\":\n",
" temperature_converter()"
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment