-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPython2.html
174 lines (170 loc) Β· 12.3 KB
/
Python2.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
<!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="py2background">
<div class="python2heading">
<h2><span style="background-color: white; color: black; padding: 5px; border-radius: 5px;">πΎ</span> Journey Through Python's Forest: Part 2 <span style="background-color: white; color: black; padding: 5px; border-radius: 5px;">πΎ</span></h2><br>
<p>"Hey adventurers do you know, as you tread deeper into Python's enchanted forest, untold magic awaits! Discover treasures in variables, traverse infinite paths with loops, and wield powerful spells. Ready your map, steel your courage, and uncover the secrets that lie within these mystical trees! π²β¨"</p>
</div>
</div>
<section>
<div class="topicbackground1">
<div class="topiccontent">
<h3>π² Variables: Storing Forest Treasures</h3>
<p>Imagine you're deep in the forest, and you come across treasures that need to be stored for your journey. Variables in Python are like <b>enchanted pouches</b> where you can safely store these treasures until you need them.</p>
<h4>π§ββοΈ Example</h4>
<div class="codebackground">
<p>treasure = "Golden Apple"<br>gold_coins = 100</p>
</div>
<ul>
<li><b><em>"<u>treasure</u>"</em></b> is the name of the pouch, and it holds a magical text string:<b><em>"<u>Golden Apple</u>"</em></b>.</li>
<li><b><em>"<u>gold_coins</u>"</em></b> is another pouch, storing an integer:<b><em>"<u>100</u>"</em></b>.</li>
</ul><br>
<p>Just like opening a pouch to check its contents, you can use the <b>"print()"</b> function to display the stored treasures:</p>
<p>► print(treasure) <span style="opacity: 0.5; font-size: 100%;"># Output: Golden Apple</span><br>► print(gold_coins) <span style="opacity: 0.5; font-size: 100%;"># Output: 100</span></p><br>
<a href="./compiler.html" class="tryitbutton" target="_blank">Try It</a><br><br>
</div>
</div>
<div class="topicbackground2">
<div class="topiccontent">
<h3>π³ Data Types: Types of Forest Items</h3>
<p>Every treasure you pick up has a specific type, which determines how you can use it. Python classifies treasures into various types of forest items:</p>
<ul>
<li><b>String(str)</b> : Holds words or magical spells, like<b><em>"<u>Golden Apple</u>"</em></b>.</li>
<li><b>Integer (int)</b> : Stores whole numbers, such as<b><em><u>100</u></em></b> trees.</li>
<li><b>Float (float)</b> : Contains precise numbers with decimals, like the magic level of <b><em><u>95.5</u></em></b>.</li>
<li><b>Boolean (bool)</b> : Represents truth, like whether a path is safe<b><em>(<u> True </u>)</em></b> or not <b><em>(<u> False </u>)</em></b>.</li>
</ul><br>
<h4>π§ββοΈ Example</h4>
<div class="codebackground">
<p><span style="opacity: 0.5; font-size: 100%;"># Types of forest items</span></p>
<p>forest_name = "Enchanted Woods" <span style="opacity: 0.5; font-size: 100%;"># String</span></p>
<p>trees_count = 500 <span style="opacity: 0.5; font-size: 100%;"> # Integer</span></p>
<p>magic_level = 99.5 <span style="opacity: 0.5; font-size: 100%;"># Float</span></p>
<p>is_safe = True <span style="opacity: 0.5; font-size: 100%;"># Boolean</span></p>
</div>
<p>You can use Python's <b><u>type()</u></b> function to uncover the nature of the treasure:</p>
<div class="codebackground">
<p>print(type(forest_name)) <span style="opacity: 0.5; font-size: 100%;"># Output:<class 'str'></span></p>
<p>print(type(trees_count)) <span style="opacity: 0.5; font-size: 100%;"># Output:<class 'int'></span></p>
</div>
<a href="./compiler.html" class="tryitbutton" target="_blank">Try It</a><br><br>
</div>
</div>
<div class="topicbackground1">
<div class="topiccontent">
<h3>π Input: Talking to the Forest</h3>
<p>The forest is alive with whispers. Sometimes, you need to ask it for guidance. Python's <em><b>input()</b></em> function lets you interact with the forest, gathering wisdom from its depths.</p>
<h4>π§ββοΈ Example</h4>
<div class="codebackground">
<p>name = input()<br>print("Welcome to the forest, brave " + name + "!")<span style="opacity: 0.5; font-size: 100%;"># Output: Welcome to the forest, brave devourer(name)!</span></p>
</div>
<p>Here, <b>"input()"</b> pauses the program and waits for the adventurerβs response. The name they enter becomes part of the forest's story!</p><br>
<a href="./compiler.html" class="tryitbutton" target="_blank">Try It</a><br><br>
</div>
</div>
<div class="topicbackground2">
<div class="topiccontent">
<h3>πͺ΅ Conditional Statements: Choosing a Path</h3>
<p>The forest often presents you with forks in the trail, where you must decide your next step. Conditional statements <em><b>(if, elif, else)</b></em> act as your compass, guiding you based on the situation.</p>
<h4>π§ββοΈ Syntax:</h4>
<div class="codebackground">
<p>if condition:</p>
<pre> # Do something</pre>
<p>elif another_condition:</p>
<pre> # Do something else</pre>
<p>else:</p>
<pre> # Default action</pre>
</div>
<h4>Example:</h4>
<p>Imagine you found a treasure chest:</p>
<div class="codebackground">
<p>treasure = "Golden Apple"</p><br>
<p>if treasure == "Golden Apple":</p>
<pre> print("You found a rare treasure!")</pre>
<p>elif treasure == "Silver Coin":</p>
<pre> print("A shiny coin!")</pre>
<p>else:</p>
<pre> print("Keep searching...")</pre>
</div>
<p>Here, Python checks each condition until one is <b>True.</b> If none match, the default ( <b><u>else:</u></b> ) action is taken.</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> Variables:</em></b><br>Your magical backpacks for storing treasures like <b>"Golden Apple"</b> or <b>100 gold coins.</b> Easily summon them with <b><u>print()</u>.</b> π§³</p><br>
<p><b>2οΈβ£<em> Data Types:</em></b><br>Every treasure has a typeβ<b>strings</b> (text like <em>"Golden Apple"</em>), <b>integers</b> (whole numbers like <em>100</em>), <b>floats</b> (decimals like <em>95.5</em>), and<b> booleans</b> (True/False for clues). Recognizing their type ensures you use them wisely. πͺ</p><br>
<p><b>3οΈβ£<em> Input:</em></b><br>Speak to the forest using <em>input()</em>to gather names, clues, or any secrets it holds. For example, ask an adventurer their name and greet them. π£οΈ</p><br>
<p><b>4οΈβ£<em> Conditionals:</em></b><br>At every fork in the trail, use <em>(if,elif & else)</em> as your compass to decide which path to take, based on the conditions you encounter. π§</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: Treasure Tracker:</b></p>
<p>☞ Create a program that asks the adventurer for their name and their favorite treasure. Then print a message like:</p>
<p><em>"Brave [name], your favorite treasure, [treasure], is waiting deep in the forest!"</em></p><br>
<a href="./compiler.html" class="tryitbutton" target="_blank">Try It</a>
<hr style="margin-bottom: 30px;" noshade>
<p><b>π Exercise 2: Forest Guard's Riddle:</b></p>
<p>☞ Write a program that checks if an adventurer can pass the forest gate.</p>
<ul>
<li>If the password is <em>"GoldenKey"</em>, print <em>"Access Granted!"</em></li>
<li>Otherwise, print <em>"Wrong password! The forest remains closed."</em></li>
</ul><br>
<a href="./compiler.html" class="tryitbutton" target="_blank">Try It</a>
<hr style="margin-bottom: 30px;" noshade>
<p><b>π Exercise 3: Trail Counter:</b></p>
<p>☞ Write a loop that prints the message:</p>
<p><em>"You take step [step number] deeper into the forest..."</em></p>
<p>for steps 1 to 10. At the end, print<b> "You've reached the heart of the forest!"</b></p><br>
<a href="./compiler.html" class="tryitbutton" target="_blank">Try It</a>
</div>
</div>
<div class="applause">
<h3>π Applause Echoes Through the Forest! π</h3>
<p>Adventurer, you've ventured further into Python's magical forest and conquered the second trails of Python's enchanted forest! π²β¨ From wielding variables like magical tools to mastering the art of decisions with conditionals, you've proven your worth as a true explorer. The trees whisper your name in admiration, and the treasures you've uncovered shine bright. π</p><br>
<p>But this is just the beginning! Beyond this clearing lies even greater mysteries: loops that guide endless paths, functions that cast powerful spells, and maps to treasures untold. πΊοΈβ¨</p>
<p>Take a deep breath, steady your resolve, and step boldly forward. The forest awaits, its secrets ready to unfold for those brave enough to continue!</p>
</div>
</section>
<section class="secondPage">
<a href="Python1.html" class="previousbutton">βͺ "Wanna revisit your steps?" β¨</a>
<a href="Python3.html" class="nextbutton">πΎ Onward, to the next chapter! β©</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>