1+ {
2+ "nbformat" : 4 ,
3+ "nbformat_minor" : 0 ,
4+ "metadata" : {
5+ "colab" : {
6+ "provenance" : [],
7+ "authorship_tag" : " ABX9TyP5+k6gq7UpXl9RJk/WI5/z" ,
8+ "include_colab_link" : true
9+ },
10+ "kernelspec" : {
11+ "name" : " python3" ,
12+ "display_name" : " Python 3"
13+ },
14+ "language_info" : {
15+ "name" : " python"
16+ }
17+ },
18+ "cells" : [
19+ {
20+ "cell_type" : " markdown" ,
21+ "metadata" : {
22+ "id" : " view-in-github" ,
23+ "colab_type" : " text"
24+ },
25+ "source" : [
26+ " <a href=\" https://colab.research.google.com/github/KhurramDevOps/Python_Learning/blob/master/recursion_prc.ipynb\" target=\" _parent\" ><img src=\" https://colab.research.google.com/assets/colab-badge.svg\" alt=\" Open In Colab\" /></a>"
27+ ]
28+ },
29+ {
30+ "cell_type" : " code" ,
31+ "execution_count" : 5 ,
32+ "metadata" : {
33+ "colab" : {
34+ "base_uri" : " https://localhost:8080/"
35+ },
36+ "id" : " Q5fDcC9fpY0G" ,
37+ "outputId" : " 66730b39-3460-43ed-c36a-c6208f94143b"
38+ },
39+ "outputs" : [
40+ {
41+ "output_type" : " stream" ,
42+ "name" : " stdout" ,
43+ "text" : [
44+ " olleh\n "
45+ ]
46+ }
47+ ],
48+ "source" : [
49+ " def reverse_str(s):\n " ,
50+ " if len(s) == 0:\n " ,
51+ " return \"\"\n " ,
52+ " return s[-1] + reverse_str(s[:-1])\n " ,
53+ " \n " ,
54+ " print(reverse_str(\" hello\" ))"
55+ ]
56+ },
57+ {
58+ "cell_type" : " code" ,
59+ "source" : [
60+ " def count_occ(lst,target,index):\n " ,
61+ " count = 0\n " ,
62+ " if index == len(lst):\n " ,
63+ " return 0\n " ,
64+ " elif lst[index] == target:\n " ,
65+ " count = 1\n " ,
66+ " return count + count_occ(lst,target,index+1)\n " ,
67+ " \n " ,
68+ " print(count_occ([1,2,3,4,5,1,2,1],2,0))"
69+ ],
70+ "metadata" : {
71+ "colab" : {
72+ "base_uri" : " https://localhost:8080/"
73+ },
74+ "id" : " 4c034-KBptDt" ,
75+ "outputId" : " 18fa7f0b-5035-4a93-e8d9-20d11a5cf9d0"
76+ },
77+ "execution_count" : 28 ,
78+ "outputs" : [
79+ {
80+ "output_type" : " stream" ,
81+ "name" : " stdout" ,
82+ "text" : [
83+ " 2\n "
84+ ]
85+ }
86+ ]
87+ },
88+ {
89+ "cell_type" : " code" ,
90+ "source" : [
91+ " def find_max(lst,index =0):\n " ,
92+ " if index == len(lst)-1:\n " ,
93+ " return lst[index]\n " ,
94+ " \n " ,
95+ " elif lst[index] > find_max(lst,index+1):\n " ,
96+ " return lst[index]\n " ,
97+ " else:\n " ,
98+ " return find_max(lst,index+1)\n " ,
99+ " \n " ,
100+ " print(find_max([1,2,3,4,5,6,7,8,9,120,11]))"
101+ ],
102+ "metadata" : {
103+ "colab" : {
104+ "base_uri" : " https://localhost:8080/"
105+ },
106+ "id" : " WkAMtdi8rrzW" ,
107+ "outputId" : " 516a096d-6f79-40fa-9ad8-49240c0ee599"
108+ },
109+ "execution_count" : 34 ,
110+ "outputs" : [
111+ {
112+ "output_type" : " stream" ,
113+ "name" : " stdout" ,
114+ "text" : [
115+ " 120\n "
116+ ]
117+ }
118+ ]
119+ },
120+ {
121+ "cell_type" : " code" ,
122+ "source" : [],
123+ "metadata" : {
124+ "id" : " DTI6yYbPyVO8"
125+ },
126+ "execution_count" : null ,
127+ "outputs" : []
128+ }
129+ ]
130+ }
0 commit comments