-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPython3.html
176 lines (174 loc) Β· 11.3 KB
/
Python3.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Python Essentials</title>
<link rel="stylesheet" href="python.css">
</head>
<body>
<nav class="navbar">
<div class="logo">
<a href="./index.html">
CODE<span style="color: #ff6f61;">FOAD</span>
</a>
</div>
<ul class="navigationlinks">
<li><a href="./index.html">Home</a></li>
<li class="tutdropdown">
<a>Tutorials</a>
<ul class="tutorialdropdownitems">
<li><a href="./Python1.html">Python Essentials</a></li>
<li><a href="./bashscripting.html">Bash Scripting</a></li>
<li><a href="./html.html">HTML</a></li>
<li><a href="./css.html">CSS</a></li>
</ul>
<li><a href="./index.html#aboutus">About Us</a></li>
<li><a href="./contactus.html">Contact</a></li>
<li><a href="./login.html" class="loginbutton">Login</a></li>
</ul>
</nav>
<div class="py3background">
<div class="python2heading">
<h2><span style="background-color: white; color: black; padding: 5px; border-radius: 5px;">πΎ</span> Journey Through Python's Forest: Part 3 <span style="background-color: white; color: black; padding: 5px; border-radius: 5px;">πΎ</span></h2><br>
<p>"Brave adventurers, your journey grows ever more thrilling! π Beyond the dense trees lies the power to organize treasures with lists, chart hidden trails with dictionaries, and master spells (functions) to shape the forest to your will. The magic intensifies, and so does the challengeβare you ready to venture further into the unknown? π³β¨"</p>
</div>
</div>
<section>
<div class="topicbackground1">
<div class="topiccontent">
<h3>π Loops: Walking Through the Forest</h3>
<p>Some paths in the forest seem endless, like counting all the trees or collecting treasures scattered around. Loops help you traverse these repetitive trails effortlessly.</p>
<h4>While Loop: Continue walking until the condition is met.</h4>
<div class="codebackground">
<p>steps = 0</p>
<p>while steps < 5:</p>
<pre> print("Step:", steps)</pre>
<pre> steps += 1</pre>
</div>
<p>This loop keeps walking until it takes 5 steps. Each iteration updates the <b><em>steps</em></b> count.</p>
<h4>For Loop: Walk through a predefined list of treasures.</h4>
<div class="codebackground">
<p>treasures = ["Golden Apple", "Silver Coin", "Emerald Gem"]</p><br>
<p>for treasure in treasures:</p>
<pre> print("Found:", treasure)</pre>
</div>
<p>Here, the adventurer visits each item in the list, one step at a time.</p><br>
<a href="./compiler.html" class="tryitbutton" target="_blank">Try It</a><br><br>
</div>
</div>
<div class="topicbackground2">
<div class="topiccontent">
<h3>π Functions: Forest Spells</h3>
<p>Sometimes, you'll need to cast magic spells (functions) to perform tasks repeatedly without rewriting the same code. Functions are your spellbooks in Python.</p>
<h4>Syntax:</h4>
<div class="codebackground">
<p>def spell_name(parameters):</p>
<pre style="opacity: 0.5; font-size: 100%;"> # Perform magic</pre>
<pre> return result</pre>
</div>
<h4>Example:</h4>
<div class="codebackground">
<p>def find_treasure(treasure_name):</p>
<pre> print("You found a magical " + treasure_name + "!")</pre><br>
<p>find_treasure("Golden Apple")</p>
<p>find_treasure("Silver Coin")</p>
</div>
<p>By defining the function<b><em> find_treasure()</em>, </b>you can call it anytime to describe treasures.</p><br>
<a href="./compiler.html" class="tryitbutton" target="_blank">Try It</a><br><br>
</div>
</div>
<div class="topicbackground1">
<div class="topiccontent">
<h3>πΏ Lists: Bags of Treasures</h3>
<p>When your inventory grows, it's best to organize your treasures in a bag. Python's lists let you collect and manage multiple items.</p>
<h4>Example:</h4>
<div class="codebackground">
<p>bag = ["Golden Apple", "Silver Coin", "Emerald Gem"]</p>
<pre>print(bag[0]) <span style="opacity: 0.5; font-size: 100%;" ># Output: Golden Apple </span> </pre>
<p>bag.append("Ruby")<span style="opacity: 0.5; font-size: 100%;" > # Add a new treasure</span> </p>
<pre>print(bag)<span style="opacity: 0.5; font-size: 100%;" > # Output: ['Golden Apple', 'Silver Coin', 'Emerald Gem', 'Ruby']</span></pre>
</div>
<p>You can<b><em> add, remove, or access items </em></b>from the list, just like rummaging through your backpack!</p><br>
<a href="./compiler.html" class="tryitbutton" target="_blank">Try It</a><br><br>
</div>
</div>
<div class="topicbackground2">
<div class="topiccontent">
<h3>π₯ Dictionaries: Forest Maps</h3>
<p>Dictionaries are your <b><em>treasure maps</em>, </b>linking treasures to their hiding spots.</p>
<h4>Example:</h4>
<div class="codebackground">
<p>treasure_map = {</p>
<pre>"Golden Apple": "Tree of Eternity",</pre>
<pre>"Silver Coin": "Riverbed",</pre>
<pre>"Emerald Gem": "Dragon's Cave"</pre>
<p>}</p>
<p>print(treasure_map["Golden Apple"]) <span style="opacity: 0.5; font-size: 100%;" > # Output: Tree of Eternity</span></p>
</div>
<p><em>Want to display all the locations? Use a loop:</em></p>
<div class="codebackground">
<p>for treasure, location in treasure_map.items():</p>
<pre> print(treasure + " is hidden at the " + location + ".")</pre>
</div>
<p>By defining the function<b><em> find_treasure()</em>, </b>you can call it anytime to describe treasures.</p><br>
<a href="./compiler.html" class="tryitbutton" target="_blank">Try It</a><br><br>
</div>
</div>
<div class="revisionbackground">
<div class="revision">
<h3>π² Forest Trail Recap π²</h3><br>
<p><b>1οΈβ£<em> Loops:</em></b><br>Use loops to guide you through repetitive tasks. <b>While</b> loops walk until the job is done, and <b>for</b> loops traverse set paths, like checking treasures in a bag. π</p><br>
<p><b>2οΈβ£<em> Functions:</em></b><br>Cast magical spells (functions) to perform tasks whenever you need. Define once, reuse endlessly(By Calling the function). πͺ</p><br>
<p><b>3οΈβ£<em> Lists:</em></b><br>Think of lists as enchanted bags that hold multiple treasures. Add, remove, or access items with ease. π</p><br>
<p><b>4οΈβ£<em> Dictionaries:</em></b><br>Use dictionaries as forest maps, pairing treasures with their secret locations. Retrieve hidden wonders with just a name. πΊοΈ</p><br>
<p>πWith these tools, you're ready for deeper adventures into Python's enchanted forest! π³</p><br><br>
</div>
</div>
<div class="exercisesbackground">
<div class="exercises">
<h3><b><em>π³ Forest Fun Exercises π³</em></b></h3><br>
<p><b>π Exercise 1: Looping Through Forest Paths</b></p>
<p>☞ The forest has 10 magical trees, each with a unique glow. Write a program to count each tree and print:</p>
<p>"Tree 1 glows brightly!"<br>"Tree 1 glows brightly!"<br>.<br>.<br>"Tree 1 glows brightly!"</p>
<p><em>(Hint: Use a for loop.)</em></p><br>
<a href="./compiler.html" class="tryitbutton" target="_blank">Try It</a>
<hr style="margin-bottom: 30px;" noshade>
<p><b>π Exercise 2: The Treasure Map</b></p>
<p>☞ Create a <b>treasure map dictionary</b> to store treasures and their locations:</p>
<ul>
<li><b>Golden Apple</b>β "Tree of Eternity"</li>
<li><b>Silver Coin</b>β "Riverbed"</li>
<li><b>Emerald Gem</b>β "Dragon's Cave"</li>
</ul>
<p>Write a program that lets adventurers input the treasure name and outputs its location. <em>(Hint: Use a dictionary and input()).</em></p><br>
<a href="./compiler.html" class="tryitbutton" target="_blank">Try It</a>
<hr style="margin-bottom: 30px;" noshade>
<p><b>π Exercise 3: The Treasure Bag</b></p>
<p>☞ Adventurers have a bag filled with treasures: <b><em>["Golden Apple", "Silver Coin", "Emerald Gem"]</em>.</b></p>
<ul>
<li>Add <b>"Ruby"</b> to the bag.</li>
<li>Remove the <b>"Silver Coin".</b></li>
<li>Print the updated bag of treasures.</li>
</ul>
<p><em>(Hint: Use list methods like append() and remove().)</em></p><br>
<a href="./compiler.html" class="tryitbutton" target="_blank">Try It</a>
<hr style="margin-bottom: 30px;" noshade>
</div>
</div>
<div class="applause">
<h3>π Applause Echoes Through the Forest! π</h3>
<p>You've done it, adventurer! By mastering loops, lists, and dictionaries, you've proven your courage and skill in navigating Python's enchanted forest. The trees whisper your name in awe! π²β¨</p><br>
<p>π With these skills, you've unlocked the outer trails of Python's enchanted forest! To venture into the heart of the forest, uncover its deepest secrets, and embark on even more thrilling adventures, continue your journey here β‘οΈ.</p>
</div>
</section>
<section class="secondPage">
<a href="Python2.html" class="previousbutton">βͺ "Wanna revisit your steps?" β¨</a>
<a href="https://www.w3schools.com/python/default.asp" class="nextbutton" target="_blank">πΎ Forge the path ahead β©</a>
</section>
<footer>
<div class="footer-container">
<p class="footer-text">Β© 2024 Made with β€οΈ by <span class="highlight">Rohan Kumar</span>, <span class="highlight">Yashraj Chowhan</span>, and <span class="highlight">Suraj Kulkarni</span>.</p>
<p class="footer-text">Empowering the world, one line of code at a time. π</p>
</div>
</footer>