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
93 changes: 66 additions & 27 deletions Intro2Python/Module1-DataTypes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -983,10 +983,13 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": []
"source": [
"s = \"Utah's SNOTEL sites are recording below average snow this year\"\n",
"x = len(s)"
]
},
{
"cell_type": "markdown",
Expand All @@ -998,10 +1001,23 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s.endswith(\"year\")"
]
},
{
"cell_type": "markdown",
Expand All @@ -1019,10 +1035,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"There are 62 SNOTEL sites in Utah.\n"
]
}
],
"source": [
"print(f'There are {x} SNOTEL sites in Utah.')"
]
},
{
"cell_type": "markdown",
Expand All @@ -1034,10 +1060,23 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"data": {
"text/plain": [
"7"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s.count(\"e\")"
]
},
{
"cell_type": "markdown",
Expand All @@ -1055,10 +1094,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"USGS in situ monitoring sites support regional water management activities\n"
]
}
],
"source": [
"string1 = 'SNOTEL in situ monitoring sites support regional water management activities'\n",
"string2 = string1.replace(\"SNOTEL\", \"USGS\")\n",
"print(string2)"
]
},
{
"cell_type": "markdown",
Expand All @@ -1078,19 +1129,7 @@
"kernelspec": {
"display_name": "p310env",
"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.10.19"
"name": "p310env"
},
"latex_envs": {
"LaTeX_envs_menu_present": true,
Expand Down
56 changes: 39 additions & 17 deletions Intro2Python/Module2-Conditionals.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,15 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"string = 'There are approximately 114 SNOTEL sites in Utah, as a part of the Natural Resouces Conservation Service (NRCS) and ~150 USGS NWIS streamflow monitoring gages.'\n",
"\n",
"if len(string) > 100:\n",
" print(\"String has more than 100 characters\")\n",
"\n",
"else:\n",
" print(\"String has less than or exsctly 100 characters\")"
]
},
{
"cell_type": "markdown",
Expand All @@ -161,7 +169,9 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"string.count(\" \")"
]
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -194,7 +204,19 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"letter1 = 'USGS sites'\n",
"letter2 = 'SNOTEL sites'\n",
"\n",
"if string.count(letter1) > string.count(letter2):\n",
" print(f\"There are more {letter1} than {letter2} \")\n",
"\n",
"elif string.count(letter2) > string.count(letter1):\n",
" print(f\"There are more {letter2} than {letter1} \")\n",
"\n",
"else: \n",
" print(f\"There are exactly the same number {letter1} and {letter2}\")"
]
},
{
"cell_type": "markdown",
Expand All @@ -210,7 +232,19 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"l1 = \"USGS\"\n",
"l2 = 'SNOTEL'\n",
"\n",
"if string.count(l1) > string.count(l2):\n",
" print(f\"There are more {l1} than {l2} \")\n",
"\n",
"elif string.count(l2) > string.count(l1):\n",
" print(f\"There are more {l2} than {l1} \")\n",
"\n",
"else: \n",
" print(f\"There are exactly the same number {l1} and {l2}\")"
]
},
{
"cell_type": "markdown",
Expand All @@ -230,19 +264,7 @@
"kernelspec": {
"display_name": "p310env",
"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.10.19"
"name": "p310env"
},
"latex_envs": {
"LaTeX_envs_menu_present": true,
Expand Down
33 changes: 17 additions & 16 deletions Intro2Python/Module3-DataStructures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,10 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"L2 = ['Hi', 'Hello', 'Hi!', 'Hey', 'Hi', 'hey', 'Hey']\n",
"print(list(set(L2)))"
]
},
{
"cell_type": "markdown",
Expand All @@ -833,7 +836,12 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"d = {2: 122, 3: 535, 't': 'T', 'rum': 'cola'}\n",
"\n",
"for n in list(d):\n",
" print(d[n])"
]
},
{
"cell_type": "markdown",
Expand All @@ -853,7 +861,12 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"s1 = ['HE170B', 'HE210B', 'HE190A', 'HE200A', 'HE210A', 'HE210A']\n",
"s2 = ['HE200A', 'HE210A', 'HE240A', 'HE200A', 'HE210B', 'HE340A']\n",
"\n",
"print(set(s1).intersection(set(s2)))"
]
},
{
"cell_type": "markdown",
Expand All @@ -873,19 +886,7 @@
"kernelspec": {
"display_name": "p310env",
"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.10.19"
"name": "p310env"
},
"latex_envs": {
"LaTeX_envs_menu_present": true,
Expand Down
23 changes: 8 additions & 15 deletions Intro2Python/Module4-SlicingAndIndexing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,10 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"L1 = [10, 20, 30, 40, 50, 60]\n",
"print(L1[0], L1[-1])"
]
},
{
"cell_type": "markdown",
Expand All @@ -336,7 +339,9 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"print(L1[L1.index(20):(L1.index(40)+1)])"
]
},
{
"cell_type": "markdown",
Expand All @@ -356,19 +361,7 @@
"kernelspec": {
"display_name": "p310env",
"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.10.19"
"name": "p310env"
},
"latex_envs": {
"LaTeX_envs_menu_present": true,
Expand Down
Loading