Skip to content

Commit b7f6b38

Browse files
committed
Python Basics
1 parent 007ae5e commit b7f6b38

File tree

1 file changed

+149
-5
lines changed

1 file changed

+149
-5
lines changed

Diff for: 01.Python Basics.ipynb

+149-5
Original file line numberDiff line numberDiff line change
@@ -466,28 +466,172 @@
466466
"outputs": [],
467467
"source": [
468468
"def square(x):\n",
469-
" =x+x\n",
469+
" y=x+x\n",
470470
" return(y)"
471471
]
472472
},
473473
{
474474
"cell_type": "code",
475-
"execution_count": 20,
475+
"execution_count": 21,
476476
"metadata": {},
477477
"outputs": [
478478
{
479479
"data": {
480480
"text/plain": [
481-
"'hellohello'"
481+
"20"
482+
]
483+
},
484+
"execution_count": 21,
485+
"metadata": {},
486+
"output_type": "execute_result"
487+
}
488+
],
489+
"source": [
490+
"square(10)"
491+
]
492+
},
493+
{
494+
"cell_type": "code",
495+
"execution_count": 22,
496+
"metadata": {},
497+
"outputs": [
498+
{
499+
"data": {
500+
"text/plain": [
501+
"10"
502+
]
503+
},
504+
"execution_count": 22,
505+
"metadata": {},
506+
"output_type": "execute_result"
507+
}
508+
],
509+
"source": [
510+
"square(2) + square(3)"
511+
]
512+
},
513+
{
514+
"cell_type": "code",
515+
"execution_count": 25,
516+
"metadata": {},
517+
"outputs": [],
518+
"source": [
519+
"def sum_of_squares(x, y):\n",
520+
" return square(x) + square(y)"
521+
]
522+
},
523+
{
524+
"cell_type": "code",
525+
"execution_count": 26,
526+
"metadata": {},
527+
"outputs": [
528+
{
529+
"data": {
530+
"text/plain": [
531+
"10"
482532
]
483533
},
484-
"execution_count": 20,
534+
"execution_count": 26,
485535
"metadata": {},
486536
"output_type": "execute_result"
487537
}
488538
],
489539
"source": [
490-
"square(x)"
540+
"sum_of_squares(2, 3)"
541+
]
542+
},
543+
{
544+
"cell_type": "code",
545+
"execution_count": 27,
546+
"metadata": {},
547+
"outputs": [],
548+
"source": [
549+
"f = square"
550+
]
551+
},
552+
{
553+
"cell_type": "code",
554+
"execution_count": 28,
555+
"metadata": {},
556+
"outputs": [
557+
{
558+
"data": {
559+
"text/plain": [
560+
"8"
561+
]
562+
},
563+
"execution_count": 28,
564+
"metadata": {},
565+
"output_type": "execute_result"
566+
}
567+
],
568+
"source": [
569+
"f(4)"
570+
]
571+
},
572+
{
573+
"cell_type": "code",
574+
"execution_count": 30,
575+
"metadata": {},
576+
"outputs": [],
577+
"source": [
578+
"def fxy(f, x, y):\n",
579+
" return f(x) + f(y)"
580+
]
581+
},
582+
{
583+
"cell_type": "code",
584+
"execution_count": 31,
585+
"metadata": {},
586+
"outputs": [
587+
{
588+
"data": {
589+
"text/plain": [
590+
"10"
591+
]
592+
},
593+
"execution_count": 31,
594+
"metadata": {},
595+
"output_type": "execute_result"
596+
}
597+
],
598+
"source": [
599+
"\n",
600+
"fxy(square, 2, 3)"
601+
]
602+
},
603+
{
604+
"cell_type": "code",
605+
"execution_count": 36,
606+
"metadata": {},
607+
"outputs": [
608+
{
609+
"name": "stdout",
610+
"output_type": "stream",
611+
"text": [
612+
"0 0\n"
613+
]
614+
}
615+
],
616+
"source": [
617+
"x = 0\n",
618+
"y = 0\n",
619+
"def incr(x):\n",
620+
" y = x + 1\n",
621+
" return y \n",
622+
"incr(5)\n",
623+
"print(x, y)"
624+
]
625+
},
626+
{
627+
"cell_type": "code",
628+
"execution_count": 38,
629+
"metadata": {},
630+
"outputs": [],
631+
"source": [
632+
"pi = 3.14\n",
633+
"def area(r):\n",
634+
" return pi*r*r"
491635
]
492636
},
493637
{

0 commit comments

Comments
 (0)