-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path2python.html
More file actions
181 lines (159 loc) · 4.4 KB
/
2python.html
File metadata and controls
181 lines (159 loc) · 4.4 KB
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
177
178
179
180
181
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Python Chapter 2 - Variables & Data Types</title>
<style>
body {
font-family: 'Segoe UI', sans-serif;
background: #f9fafb;
margin: 0;
padding: 0;
}
header {
background: #2d3748;
color: white;
text-align: center;
padding: 20px 0;
}
.section {
background: white;
margin: 20px;
padding: 20px;
border-radius: 15px;
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}
h2 {
color: #2b6cb0;
}
p, li {
line-height: 1.6;
}
.code-block, .output-block {
background: #f4f4f4;
font-family: monospace;
padding: 10px;
border-left: 4px solid #4299e1;
margin-top: 10px;
border-radius: 5px;
}
.output-block {
background: #e6ffe6;
border-left: 4px solid #38a169;
}
.wrong {
background: #ffe6e6;
border-left: 4px solid #e53e3e;
}
ul {
padding-left: 20px;
}
</style>
</head>
<body>
<header>
<h1>Chapter 2: Variables & Data Types in Python</h1>
<p>Variables banana, data types samajhna, aur input-output karna – sab kuch with rules aur examples!</p>
</header>
<div class="section">
<h2>1. Variables in Python</h2>
<p>Variable ek container jaisa hota hai jisme hum koi value store karte hain.</p>
<h3>Rules of Writing Variables:</h3>
<ul>
<li>Variable ka naam letter ya underscore (_) se start hona chahiye</li>
<li>Kabhi bhi number se start mat karo (❌ 2name = "abc")</li>
<li>No special characters allowed (❌ name$ = "abc")</li>
<li>Spaces nahi aani chahiye (❌ my name = "abc")</li>
<li>Python ke keywords (if, else, class) ka use variable naam ke liye mat karo</li>
</ul>
<h3>✅ Right Way:</h3>
<div class="code-block">
name = "Amit"<br>
age = 25
</div>
<h3>❌ Wrong Way:</h3>
<div class="code-block wrong">
2name = "Amit" # ❌ Invalid: number se start nahi ho sakta<br>
my name = "Amit" # ❌ Invalid: spaces not allowed<br>
class = "ABC" # ❌ Invalid: 'class' is a keyword
</div>
<h3>Output:</h3>
<div class="output-block">
Amit<br>
25
</div>
</div>
<div class="section">
<h2>2. Input from User</h2>
<p><code>input()</code> function user se data lene ke liye use hota hai. By default yeh string deta hai.</p>
<div class="code-block">
name = input("Enter your name: ")<br>
print("Welcome", name)
</div>
<div class="output-block">
Enter your name: Ravi<br>
Welcome Ravi
</div>
<h3>Common Mistake:</h3>
<div class="code-block wrong">
age = input("Enter age: ")<br>
print(age + 5) # ❌ Error: string + int not allowed
</div>
<h3>Correct Way:</h3>
<div class="code-block">
age = int(input("Enter age: "))<br>
print(age + 5)
</div>
<div class="output-block">
Enter age: 20<br>
25
</div>
</div>
<div class="section">
<h2>3. Data Types in Python</h2>
<ul>
<li><b>int:</b> Integer values jaise 1, 100, -5</li>
<li><b>float:</b> Decimal values jaise 3.14, -0.5</li>
<li><b>str:</b> Text ya characters, like "Hello"</li>
<li><b>bool:</b> True ya False (boolean)</li>
<li><b>complex:</b> Complex numbers like 2 + 3j</li>
</ul>
<div class="code-block">
a = 5<br>
b = 3.14<br>
c = "Hi"<br>
d = True<br>
e = 4 + 2j<br>
print(type(a), type(b), type(c), type(d), type(e))
</div>
<div class="output-block">
<class 'int'> <class 'float'> <class 'str'> <class 'bool'> <class 'complex'>
</div>
</div>
<div class="section">
<h2>4. Type Casting</h2>
<p>Type casting matlab ek data type ko dusre me badalna.</p>
<h3>✅ Right Example:</h3>
<div class="code-block">
num = "10"<br>
num = int(num)<br>
print(num + 5)
</div>
<div class="output-block">15</div>
<h3>❌ Wrong Example:</h3>
<div class="code-block wrong">
num = "ten"<br>
num = int(num) # ❌ Error: 'ten' string ko int me convert nahi kar sakte
</div>
</div>
<div class="section">
<h2>5. print() Function</h2>
<p><code>print()</code> ka use output dikhane ke liye hota hai. Kuch bhi show karna ho screen pe, print ka use hota hai.</p>
<div class="code-block">
print("Learning Python is fun!")
</div>
<div class="output-block">Learning Python is fun!</div>
</div>
</body>
</html>