Skip to content

Instantly share code, notes, and snippets.

@drcjar
Created March 30, 2021 22:33
Show Gist options
  • Save drcjar/9a68d28293e5db1db2923e8284c478b5 to your computer and use it in GitHub Desktop.
Save drcjar/9a68d28293e5db1db2923e8284c478b5 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'\\nhttps://www.mdcalc.com/estimated-expected-peak-expiratory-flow-peak-flow\\n\\nAges 5-7 years and any ethnicity:\\n\\nPEFR = [(Height, cm - 100) × 5] + 100\\n\\nAges 18-80 years, all other ethnicities:\\n\\nPEFR, male = {[(Height, m × 5.48) + 1.58] - [Age × 0.041]} × 60\\n\\nPEFR, female = {[(Height, m × 3.72) + 2.24] - [Age × 0.03]} × 60\\n'"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\"\"\"\n",
"https://www.mdcalc.com/estimated-expected-peak-expiratory-flow-peak-flow\n",
"\n",
"Ages 5-7 years and any ethnicity:\n",
"\n",
"PEFR = [(Height, cm - 100) × 5] + 100\n",
"\n",
"Ages 18-80 years, all other ethnicities:\n",
"\n",
"PEFR, male = {[(Height, m × 5.48) + 1.58] - [Age × 0.041]} × 60\n",
"\n",
"PEFR, female = {[(Height, m × 3.72) + 2.24] - [Age × 0.03]} × 60\n",
"\"\"\""
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [],
"source": [
"def get_age(prompt):\n",
" try:\n",
" value = int(input(prompt))\n",
" except ValueError:\n",
" print(\"Sorry, I didn't understand that.\")\n",
" return get_age(prompt)\n",
"\n",
" if value < 5:\n",
" print(\"Sorry, you must be at least 5 years old for us to predict your peak expiratory flow rate.\")\n",
" return get_age(prompt)\n",
" elif value > 80:\n",
" print(\"Sorry, you must be less than 80 years old for us to predict your peak expiratory flow rate.\")\n",
" return get_age(prompt)\n",
" else:\n",
" return value"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [],
"source": [
"def get_height(prompt):\n",
" try:\n",
" value = int(input(prompt))\n",
" except ValueError:\n",
" print(\"Sorry, I didn't understand that.\")\n",
" return get_height(prompt)\n",
"\n",
" if value < 0:\n",
" print(\"Sorry, you must have a positive height in cm for us to predict your peak expiratory flow rate.\")\n",
" return get_height(prompt)\n",
" elif value > 1000:\n",
" print(\"Sorry, you must be less than 1000cm tall for us to predict your peak expiratory flow rate.\")\n",
" return get_height(prompt)\n",
" else:\n",
" return value"
]
},
{
"cell_type": "code",
"execution_count": 49,
"metadata": {},
"outputs": [],
"source": [
"def get_sex(prompt):\n",
" try:\n",
" value = int(input(prompt))\n",
" except ValueError:\n",
" print(\"Sorry, I didn't understand that.\")\n",
" return get_sex(prompt)\n",
"\n",
" if value == 1:\n",
" return value\n",
" elif value == 2:\n",
" return value\n",
" else:\n",
" print(\"Sorry, I didn't understand that.\")\n",
" return get_sex(prompt)"
]
},
{
"cell_type": "code",
"execution_count": 80,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Please enter age in years: 37\n",
"Please enter height in cm: 168\n",
"Please enter your sex 1=male, 2=female: 1\n"
]
}
],
"source": [
"age = get_age('Please enter age in years: ')\n",
"height = get_height('Please enter height in cm: ')\n",
"sex = get_sex('Please enter your sex 1=male, 2=female: ')"
]
},
{
"cell_type": "code",
"execution_count": 97,
"metadata": {},
"outputs": [],
"source": [
"def predicted_pefr(age, height, sex):\n",
" if (age >= 5) & (age <= 7):\n",
" PEFR = ((height - 100) * 5) + 100\n",
" elif sex == 1:\n",
" PEFR = ((((height/100) * 5.48) + 1.58) - (age * 0.041)) * 60\n",
" elif sex == 2:\n",
" PEFR = ((((height/100) * 3.72) + 2.24) - (age * 0.03)) * 60\n",
" else:\n",
" print(\"Sorry, the input was unexpected\") \n",
" return PEFR"
]
},
{
"cell_type": "code",
"execution_count": 98,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"556.1640000000001"
]
},
"execution_count": 98,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"predicted_pefr(age,height,sex)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.12"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment