-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython.py
More file actions
362 lines (288 loc) · 6.79 KB
/
python.py
File metadata and controls
362 lines (288 loc) · 6.79 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
# -*- coding: utf-8 -*-
"""python.ipynb
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/drive/1y_jUt_j3lTDVKaZYAwzM05wnaf68JojD
## **Python Basics**
**print statement**
"""
# string values is in "" '' and """""" for multiline print sentences
print("hello")
print(''' hello
world ''')
print( 123456)
print ('it's going to rain today')
print ('it\'s going to rain today')
print ("it's going to rain today")
"""**comments**"""
# in this page i will see two numbers
# single line comment
''' doulple line and
multiple
lines
comments'''
"""**variables **"""
# placeholder
# case sensitive
# make shorw no space * even number *.. can use _ under score even_number
# can not be start with number 12334 but can be * num1 num_2 * and special number @%$
a=12
print(a)
a="hello"
print(a)
"""**Data types and user input**"""
# user input
name =input ("enter your name : ")
print(name)
age =int(input ("enter your age : "))
print(age)
# string
# default enter value in string
# floating poits 0.234, 23.5 if the user can gives value in decimal
lenght =float(input ("enter your lenght"))
print(lenght)
ep1=eval(input("enter your ep1 "))
print(ep1)
ep1=eval(input("enter your ep1 "))
print(ep1)
"""**typecastig and subtypes**"""
# conversion of one datatype to another is called type-casting
name="jon"
print (type(name))
# Implicit type casting convertion : where python itself converts one datatype to another
# Explicit type casting convertion : where the user converts one data to another
# Implicit
a=123
b=1.234
print(type(a)) # int
print(type(b)) # float
c=a+b
print(c)
print(type(c)) # float
a="123" # throw an error so we use explicit typecasting in it
b=1.234
print(type(a)) # int
print(type(b)) # float
c=a+b
print(c)
print(type(c)) # float
a="1245"
b=1.234
print(type(a)) # string
print(type(b)) # float
a=int(a)
print("After convertion a is ",type(a))
c=a+b
print(c)
print(type(c)) # float
"""**operators and operands**"""
# operators
# + - * / % // **
# // floor division
# ** power
# Arithmetic operator
a=4
b=2
print(a+b)
print(a-b)
print(a*b)
print(a/b)
print(a%b)
print(a//b) # without point value
print(a**b)
# comparison operators
print (a==b)
print (a!=b)
print (a>b)
print (a<b)
print (a>=b)
print (a<=b)
# logical operators
print(a==b and a>b)
print(3==3 and 8>7)
print(a==b or a>b)
print(not a==b)
print (not (3==3 and 8>7))
# Assignmet operators
# for asign value
score=0
score=score+1
print(score)
score+=1
print(score)
score-=1
print(score)
score*=2
print(score)
score/=2
print(score)
score%=2
print(score)
# Identity Operators
# types of identity operators
# is
# is not
a=123 # int
b="123" #string
print(a is b)
print(a is not b)
a=123
b=123
print(a is b)
print(a is not b)
# bitwise operators
# 0 1 off on
# << >> & | ^ ~
print(bin(10))
print(bin(15))
a=10
b=8
print(a&b) # AND
print(a|b) # OR
print(a^b) # XOR
print(~a)
print(a<<2) # zero fill right shift --- add vlues in right
print(a>>1)# zero fill left shift -- cut value form right and add values in left
# membership operators
# check the presence of a value in a sequence
# in
# not in
a="helllo"
print("h" in a)
print("h" not in a)
"""**conditional statements**"""
# if statement
a=10
if a>3:
print("a is greater than 3")
marks =87
if marks >=90:
print("you will get phone grade")
print("thankyou for joining")
marks=87
if marks >=90:
print("you will get phone grade")
else: # no condition with else
print("you will not get phone grade")
print("thankyou for joining")
# if - elif - else
marks =87
if marks >=90:
print("you will get A grade")
elif marks >=80:
print("you will get B grade")
elif marks >=70:
print("you will get C grade")
elif marks >=60:
print("you will get D grade")
else:
print("fail")
# nested if
if marks>=80:
print("you will get a new phone ")
if marks >=90:
print("you can go to a trip ")
else :
print ("you will not get a nothing ")
# short hand if statement
marks=87
if marks>=80: print("you will get a new phone ")
# short hand if else statement
print("you will get a new phone ") if marks>=80 else print("you will not get a nothing ") # no colon in it
"""# *problem solving*
**write a program to display a person's name,age and address in three different lines**
"""
name="jon"
age =21
address="london"
print(name)
print(age)
print(address)
"""**write a profram to swap two variables**"""
a=2
b=3
# method b temperory variable temp
temp=a
a=b
b=temp
print("value of a : ",a)
print( "value of b : ",b)
# method 2
a=30
b=40
a,b=b,a
print("value of a : ",a)
print( "value of b : ",b)
"""**write a program to convert a float into integer**"""
x=122.4
print(type(x))
x=int(x)
print(type(x))
print(x)
"""**write a program to take details from a student for ID-card and then print in different lines**"""
print ("student identity card ")
name =input ("enter your name :")
age =int(input ("enter your age :"))
address=input("enter your address :")
email=input("enter your email :")
print("name : ",name)
print("age : ",age)
print("address : ",address)
print("email : ",email)
"""**write a program to take an user input as integer then convert to float**"""
a=int(input("enter a number :"))
print(type(a))
a=float(a)
print(type(a))
print(a)
"""<!-- place holders -->
**write a program to check if a number is positive**
"""
num=int(input("enter a number :"))
if num>0:
print("number is positive")
else:
print("number is negative")
"""**write a program to check whether a number is odd and even**"""
num=int(input("enter a number :"))
if num%2==0:
print("number is even")
else:
print("number is odd")
"""**write a program to create area calculator**"""
print("++++ AREA CALCULATOR ++++++")
print("press 1 for area of circle")
print("press 2 for area of rectangle")
print("press 3 for area of triangle")
choice=int(input("enter your choice :"))
if choice==1:
radius=float(input("enter radius :"))
area=3.14*radius*radius
print("area of circle is : ",area)
print("thank you for using area calculator")
elif choice==2:
length=float(input("enter length :"))
breadth=float(input("enter breadth :"))
area=length*breadth
print("area of rectangle is : ",area)
print("thank you for using area calculator")
elif choice==3:
base=float(input("enter base :"))
height=float(input("enter height :"))
area=0.5*base*height
print("area of triangle is : ",area)
else :
print("invalid choice")
"""**write a program check whether the passed letter is a vowel or not**"""
if (letter in "aeiou") or (letter in "AEIOU") :
print("letter is vowel")
else:
print("letter is not vowel")
"""**write a program to check if a number is a single digit number , 2 digit number and so on ..., up to 5 digit**"""
num =int (input("enter a number :"))
if num<10:
print("single digit number")
elif num<100:
print("two digit number")
elif num<1000:
print("three digit number")