Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
179 changes: 179 additions & 0 deletions Ex3_ConditionEx_SharonWai.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Ex3_ConditionEx.ipynb",
"provenance": [],
"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/github/SharonWai/PythonProgramming/blob/SharonWai/Ex3_ConditionEx_SharonWai.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"source": [
"Write a program that asks the user to enter a length in centimeters. If the user enters a negative length, the program should tell the user that the entry is invalid. Otherwise, the program should convert the length to inches and print out the result. There are 2.54 centimeters in an inch.\n"
],
"metadata": {
"id": "r9njLbxcvG0w"
}
},
{
"cell_type": "code",
"source": [
"length_cm = input(\"Enter a length in centimeters: \")\n",
"length_cm = float(length_cm)\n",
"if length_cm < 0:\n",
" print (\"Entry is invalid\")\n",
"else:\n",
" inches_cm = length_cm / 2.54\n",
" length_in = inches_cm * length_cm\n",
" print(f\"{length_cm} is equal to {length_in}\")\n"
],
"metadata": {
"id": "76EFWr1AvMy4",
"outputId": "c29bec63-9afd-4a39-ff89-701d235afacf",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"execution_count": 2,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Enter a length in centimeters: 10\n",
"10.0 is equal to 39.37007874015748\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"Ask the user to enter a temperature in Celsius. The program should print a message based on the temperature:\n",
"\n",
"* If the temperature is less than -273.15, print that the temperature is invalid because it is below absolute zero.\n",
"* If it is exactly -273.15, print that the temperature is absolute 0.\n",
"* If the temperature is between -273.15 and 0, print that the temperature is below freezing.\n",
"* If it is 0, print that the temperature is at the freezing point.\n",
"* If it is between 0 and 100, print that the temperature is in the normal range.\n",
"* If it is 100, print that the temperature is at the boiling point.\n",
"* If it is above 100, print that the temperature is above the boiling point."
],
"metadata": {
"id": "zvaDTmuhvNWJ"
}
},
{
"cell_type": "code",
"source": [
"Temp = input(\"Enter a Temperature in Celsius: \")\n",
"Temp = float(Temp)\n",
"\n",
"if Temp < -273.15:\n",
" print(\"The temperature is invalid because it is below absolute zero.\")\n",
"elif Temp == -273.15:\n",
" print(\"The temperature is absolute 0.\")\n",
"elif Temp > -273.15 and Temp < 0:\n",
" print (\"The temperature is below freezing.\")\n",
"elif Temp == 0:\n",
" print (\"The temperature is at the freezing point.\")\n",
"elif Temp > 0 and Temp < 100:\n",
" print (\"The temperature is in the normal range.\")\n",
"elif Temp == 100:\n",
" print (\"The temperature is at the boiling point.\")\n",
"else:\n",
" print(\"The temperature is above the boiling point.\")"
],
"metadata": {
"id": "UiCbUIcwvqxO",
"outputId": "0326ecaa-4b6c-45a6-9cee-7ff3d6bc85bc",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"execution_count": 22,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Enter a Temperature in Celsius: 100\n",
"The temperature is at the boiling point.\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"Write a program that asks the user how many credits they have taken. If they have taken 23 or less, print that the student is a freshman. If they have taken between 24 and 53, print that they are a sophomore. The range for juniors is 54 to 83, and for seniors it is 84 and over."
],
"metadata": {
"id": "hoczytNLvrnd"
}
},
{
"cell_type": "code",
"source": [
"Credits = input(\"How many credits have you taken: \")\n",
"Credits = int(Credits)\n",
"\n",
"if Credits <= 23:\n",
" print(\"The student is a freshman.\")\n",
"elif Credits >= 24 and Credits <= 53:\n",
" print(\"The student is a sophomore.\")\n",
"elif Credits >= 54 and Credits <= 83:\n",
" print(\"The student is junior.\")\n",
"else:\n",
" print(\"The student is senior.\")\n"
],
"metadata": {
"id": "r8_O-_zLvurf",
"outputId": "91121453-1f60-494c-d8f7-d63c9d8dda28",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"execution_count": 26,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"How many credits have you taken: 85\n",
"The student is senior.\n"
]
}
]
},
{
"cell_type": "code",
"source": [],
"metadata": {
"id": "P-e4rq_8OR9-"
},
"execution_count": null,
"outputs": []
}
]
}
Loading