-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.py
More file actions
1980 lines (1797 loc) · 63.3 KB
/
Copy pathcode.py
File metadata and controls
1980 lines (1797 loc) · 63.3 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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# what is a used of Print funcation in python
"""Print funcation is a method that check the code in a terminal """
Name="Msood Rahman"
Age = 25
My_place = "New Delhi"
print("Hi my name is",Name,"and my age is",Age,"from ",My_place)
"""Comma method, F-string function, Concatenation+ to wrint print() funcation"""
ph="7303367532"
print(f"my phone nuber is {ph}")
#Coments in python
#Single Coment
#Multiple Coment means Docstrean
"""""" and''''''
#Escape Sequeances or Escape Charectar
"""
\' Single quotation Escape Sequance
\" Double quotation Escape Sequance
\n next line Escape Sequance
\b Backspace Escape Sequance
\t Tab Sequence
"""
print("Hi my name is Masood Rahman\nMy age is 25\nfrom New Delhi....")
print("Hi my name is masood rahman\bMy age is 25\bfrom new Delhi....")
print("Hi my name is \'masood rahman\'. My age is 25 from new Delhi....")
print('Hi my name is "M"\t\t\tasood Rahman')
print('Hi my name is \"Masood Rahman\"')
print("Hi my name is \\nMasood Rahman")
# Variable
"""
An according to python programming language variable it is a contaner that stored any data type
in a particula memory indexing like Stack and Heap"""
x=10
y=20
print(x*y)
# Input funcation
"""
An according to Data Analyst Input funcation is basicaly used in access the
paritucal data set in CSV file or Database is called data Input funcation.
"""
num_1=int(input("Enter first number: "))
num_2=int(input("Enter second number: "))
num_3=int(input("Enter third number: "))
Total=num_1+num_2+num_3
print(f"Now the total sum is = {Total}")
name=input("Enter your Name:")
age=input("Enter your age:")
gender=input("Enter your Gender:")
print(f"Hi {name}")
# Data Type
"""Data type specifies which type of value to store on a variable has and what mathematical relation
or logical operation can be perfomed on it without causing any eror is called Data Type. """
"""
(i) Numeric Data Types: int, float, complex
(ii) Sequence Data Types: Str, list, tuple, range
(iii) Mapping Data Type: dict
(iv) Set Data Types: set, frozenset
(v) Boolean Data Type: bool
(vii) Binary Data Types: bytes, bytearray, memoryview
(viii) None Data Type: NoneType
"""
a=[88,44.4,True,"Masood Rahman"]
print(a[1])
print(f"{type(a[1])}\n")
# Itration
print("Now we used a itration by using a for loop in list ellement step by step ")
Rahman_family=["Masood Rahman","Masooma Rahman","Rabeya Rahman"]
# first count the all ellement in a list by using len ()
Total_ellement=len(Rahman_family)
print(f"The total ellement on list = {Total_ellement}")
#Now know that in this list have three ellement have over their
for i in range(0,3):
print(Rahman_family[i])
# Itrate by Position or Index
print("----------************-------------")
Rahman_family=["Masood Rahman","Masooma Rahman","Rabeya Rahman"]
for i in range (len(Rahman_family)):
print(Rahman_family[i])
# Itrate by value
Rahman_family=["Masood Rahman","Masooma Rahman","Rabeya Rahman\n"]
for i in Rahman_family:
print(i, end=" ")
print("""#write the list your own self and print reverse\n""")
Masood_info = ["Masood Rahman", "8 May 2000", 7303367532]
# Start at index 2, end at 0, step by -1
for i in range(len(Masood_info) - 1, -1, -1):
print(Masood_info[i])
# Sequence data type str
"""Str"""
"""List :- to store any type of value in a variable like string, boolea, integer, float, double """
# Write your own list and print only even number
Num=[1,2,3,4,5,6,7,8,9,10]
print("This are even number ellement over the list ")
for i in Num:
if i %2==0:
print(i)
# Write your own list and print only odd number
Num=[1,2,3,4,5,6,7,8,9,10]
print("This are odd number ellement over the list ")
for i in Num:
if i %2!=0:
print(i)
# Write the own list and print the even number index using len()
Num=[1,2,3,4,5,6,7,8,9,10]
print("This are even number indexing ellement over the list ")
for i in range (0,len(Num)):
if Num[i] %2==0:
print(Num[i],end=" ")
#Make own your list and sum all number ellement
Num=[1,2,3,4,5,6,7,8,9,10]
total=0
for i in Num:
total=total+i
print(f"\nsum all number ellement = {total}")
#Make own your list and sum all number ellement
Num=[1,2,3,4,5,6,7,8,9,10]
print("This are even number indexing sum of ellement over the list ")
for i in range (0,len(Num)):
total=total+i
print(total)
# Make in your own list. count the number of even number present in that list
List_1=[100,99,98,97,9678,44,34,33]
count=0
for i in List_1:
if i % 2==0: # even number logic within condition
count=count+1
print(f"The even number of ellement in the list = {count}")
# Make in your own list. count the number of odd number present in that list
List_1=[100,99,98,97,96,78,44,34,33]
count=0
for i in List_1:
if i % 2!=0: # odd number logic within condition
count=count+1
print(f"The odd number of ellement in the list = {count}")
# Make in your own list. count the number of even number present and sum the all ellement
List_1 = [100, 99, 98, 97, 96, 78, 44, 34, 33]
total = 0
for i in range(0, len(List_1)):
if List_1[i] % 2 == 0:
total = total + List_1[i]
print(f"The sum of even number ellement in the list = {total}")
# Make in your own list. count the number of odd number present and sum the all ellement
num = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
count_3 = 0
count_4 = 0
for i in num:
# Check for 3 independently
if i % 3 == 0:
count_3 += 1
# Check for 4 independently
if i % 4 == 0:
count_4 += 1
print(f"Elements divisible by 3 = {count_3}")
print(f"Elements divisible by 4 = {count_4}")
# Make the list and check the whic is positive and negative
Whole_num = [-10, -8, -6, -4, -2, 0, 2, 4, 6, 8, 10]
"""-10-------------0------------10"""
count_negative = 0
count_positive = 0
for i in Whole_num:
if i <= 0:
count_negative += 1
elif i >= 0:
count_positive += 1
print(f"Negative Elements = {count_negative}")
print(f"Positive Elements = {count_positive}")
# Make the list and print the largest number in the present list
my_list=[100,101,1001,200,300,400,1000]
largest =0
for i in range (0,len(my_list)):
if my_list[i] > largest:
largest=my_list[i]
print(f"The Largest number in theis list = {largest}")
"""List :-List is a Mutable sequence data type to store any type of value in a variable like
string, boolean, integer, float is called List """
# Mutabel means to easily manupilate the present data like append and pop
# List Method append pop remove
num_1=[1,2,3,4,5,6,7,8,9,10]
print(num_1)
"""append() is to storre a data in list position"""
num_1.append(11)
print(num_1)
"""insert() is store the data by the basis of Memory Indexing which means 13 is a memory index position and data is '12'"""
num_1.insert(13,12)
print(num_1)
"""Now we used POP """
num_1.pop(-1) # last digit removed from negative indexing
print(num_1)
num_1.clear()
print(num_1)# all ellement removed by used clear() fucation
"""Write the program from user that entert the number ellement as form list"""
# Ask the user for the length of the list
length = int(input("How many numbers do you want in your list = "))
# Initialize an empty list
user_list = []
# Use a loop to populate the list
for i in range(length):
num = int(input(f"Enter element {i + 1}: ")) # i is used for enter the ellement +1 is used for Indexin
user_list.append(num)
print(f"The final List : {user_list}")
"""write the element and removed even number from the list """
list_=[1,2,3,4,5,6,7,8,9,10]
result=[]
for i in range(0,len(list_)):
if i % 2!=0:
result.append(i)
print(result)
"""Make a list which have 1 to 10 ellement over thier and
sapreate the elementas odd list and even list """
# Member ship operator in list
my_info = ["Masood Rahman", "DOB 8 May 2000", "Ph no:7303367532"]
print("Masood Rahman" in my_info)
# 2. Checks for "Sonu"
if "Sonu" in my_info:
print(True)
else:
print(False)
# 3. User input check
user_info = input("Enter the number which present on the list : ")
if my_info.count(user_info) > 0:
print(True)
else:
print(False)
"""""Make your own list and removed dulicate value"""
my_list=[1,2,3,4,5,5.5,3,4,5,"Masood Rahman"]
result=[]
for i in my_list:
if i not in result: # removed duplicate value
result.append(i)
print(result)
"""Make a list that check the element from the user if the number exisist in the list the print
the position of the element else print -1 """
My_list=[10,20,30,40,50,"Sonu",50.5]
value=input("Enter the Value to Check over the element: ")
if value in My_list:
index=My_list.index(value)
print(f"Yes the element are present = {index} index position")
else:
print(-1)
"""Make a list that from user end check the element from the user and then
copy the all element to store in revresd order"""
My_list=[]
for i in range(5):
value = int(input(f"Enter the all Element [i] = "))
My_list.append(value)
result=[]
for i in range (len(My_list)-1,-1,-1):
result.append(My_list[i])
print(f"The final list revesr formate = {result}")
"""Make a int number list and calculate the average value ot he list """
mylist=[1,2,3,4,5]
average=sum(mylist)/len(mylist)
print(average)
"""Write the progamm that check the value in a list highest occureance and print element"""
MY_list=[5,8,9,10,6,5,9,8,10,5]
result=[]
for i in MY_list:
if i not in result:
result.append(i)
highest_ocurence_value=0
highest_occurence=0
for i in result:
Count=MY_list.count(i)
print(f"{i} occure the highest value in {Count} Times ")
if Count>highest_occurence:
highest_occurence=Count
highest_ocurence_value=i
print(f"Highest occurence element is = {highest_ocurence_value}")
"""make the two list to find a common element and saved in third list as a name of result"""
num_1=[1,2,3,4,5,6,7,8,9,10]
print(f"num_1 list = {num_1}")
num_2=[5,10,15,20,25,30,35,40]
print(f"num_2 list ={num_2}")
result=[]
for i in num_1:
if i in num_2:
if num_1 not in result:
result.append(i)
print(f"The coman ellment is result list = {result}")
"""Make the list and find a second largest value value in the list without using sorting """
my_list = [10, 50, 80, 990, 880, 500, 670, 986, 980, 1020, 5024, 890, 7, 6, 4, 2, 0]
largest = float('-inf')
second_largest = float('-inf')
for i in my_list:
if i > largest:
second_largest = largest
largest = i
elif i > second_largest and i < largest:
second_largest = i
print(f"The Secod largest number in the list = {second_largest}")
"""Make the kist to make product of sum """
my_list = [10, 50, 80, 990, 880, 500, 670, 986, 980, 1020, 5024, 890, 7, 6, 4, 2]
P_Sum=1
for i in my_list:
P_Sum=P_Sum*i
print(f"The sum of product on the list {P_Sum}")
import math
my_list = [10, 50, 80, 990, 880, 500, 670, 986, 980, 1020, 5024, 890, 7, 6, 4, 2,]
print(f"The final Product using math.prod () ={math.prod(my_list)}")
"""Make a list and check the the prime number over theire or not!"""
my_list=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
for num in my_list:
factor=0
for i in range (1, num + 1):
if num%i==0:
factor+=1
if factor==2:
print(f"Prime number = {num}")
"""Make a list and split into two part"""
Orignal=[100,20,30,500]
first_halfe=Orignal[:len(Orignal)//2]
second_half=Orignal[len(Orignal)//2]
print(f"First halfe List {first_halfe}")
print(f"Second halfe List {second_half}")
# List Itration
my_list=[]
for i in range(1,21):
my_list.append(i)
print(my_list)
"""List Comprehension is the method to understand when
we enter the element on a single line of code at
list so we used Comprhension and it's faster and acurate """
mylist=[i for i in range(1,21)]
print(mylist)
num_list=["Even" if i % 2==0 else "Odd" for i in range(1,21)]
print(num_list)
"""Make a Comprhension List for even number """
Num_list=[i for i in range (1,31) if i % 2 ==0]
print(f"Even Number List = {Num_list}")
"""Make a Comprhension List for the odd number"""
Num_list = [i for i in range (1,31) if i % 2 !=0]
print(f"Odd Number List = {Num_list}")
"""Make a List which start and end with from user input element and check the thoes ellement are divde by 2 and 3"""
Start=int(input("write the starting Element = "))
End=int(input("write the ending Element = "))
List=[i for i in range (Start,End+1) if i %2 ==0 and i % 3==0]
print(List)
print("***----------********------------****\n")
# List Slicing
num=[i for i in range (1,21) ]
print(num)
a=num[0:5]
print(f"for positive slicing = {a}")
b=num[-1:-7:-1]
print(f"for Negative slicing = {b}")
c=num[10:15]
print(f"for mid value indexing= {c}")
"""Make a list Comprhension to make positve, mide, negative slicing index """
Usr_start=int(input("Enter the element start = "))
Usr_end=int(input("Enter the element to end = "))
Num=[i for i in range (Usr_start,Usr_end+1)]
a=Num[0:5]
print(f"for positive slicing at user end = {a}")
b=Num[-1:-7:-1]
print(f"for Negative slicingat at user end = {b}")
c=Num[10:15]
print(f"for mid value indexing at at user end = {c}")
count = int(input("Enter how many elements you want in the list: "))
user_list = []
result = []
for i in range(count):
val = int(input(f"Enter element {i+1}: "))
user_list.append(val)
for num in user_list:
if num % 2 != 0:
result.append(num)
"""Creating a list using prompt and make a list then we take a one old ellement pick
after that update them from the user end """
# 1. User input
total_elements = int(input("Enter how many numbers you want = "))
result = []
for i in range(total_elements):
num = int(input(f"Enter number {i+1} = "))
result.append(num)
# 2. print the output
print(f"Your final list: {result}")
index_to_update = int(input(f"Enter the index you want to update (0 to {len(result)-1}) = "))
if 0 <= index_to_update < len(result):
new_value = int(input("Enter the new value = "))
# 3. Update the element from the user end
result[index_to_update] = new_value
print(f"Updated list: {result}")
else:
print("Invalid index! Please pick a number within the list range.")
"""Enter the user input how much element you want and divide by user
input check element are divde or not divide"""
# Code
total_elements = int(input("Enter how many numbers you want = "))
result = []
for i in range(total_elements):
num = int(input(f"Enter number {i+1} = "))
result.append(num)
divisor = int(input("Enter the number to divide by: "))
divisible_list = []
not_divisible_list = []
for num in result:
if num % divisor == 0:
divisible_list.append(num)
else:
not_divisible_list.append(num)
# Print the output
print(f"\nOriginal List: {result}")
print(f"Numbers divisible by {divisor}: {divisible_list}")
print(f"Numbers not divisible by {divisor}: {not_divisible_list}")
a=[10,9,8,7,6,5,4,3,2,1, 0.5]
print(a)
a.sort()
print(f"We uppdate value using sort () and we have know {a}")
#update the data
# Index
position=a.index(0.5)
print(f"'0.5' element memeory address = {position} position")
# Now we add the value in last position of a list
a.append("Masood Rahman")
print(f"Using the append () we add the new element = {a}")
a.extend(["Masooma Rahman","Rabeya Rahman"])
print(f"Now we used extend([]) to add element in list:- \n{a}")
# now check the repetade ellement in list
repeted=a.count("Masood Rahman")
print(f"the number of 'Masood Rahman' element at count is {repeted} time")
"""Make a list which have 1 to 10 ellement over thier and
sapreate the elementas odd list and even list """
List=[1,2,3,4,5,6,7,8,9,10]
even=[]
odd=[]
for i in range(0,len(List)):
if List[i] % 2==0:
even.append(List[i])
else:
odd.append(List[i])
print(f"The Even element in this list = {even}")
print(f"The Odd element in this list = {odd}")
"""Make two list with random number and merge both in different list"""
List_1=[1,2,3,4,5]
List_2=[6,7,8,9,10]
Result=[]
for num in range(0,len(List_1)):
Result.append(num)
for num in range (0,len(List_2)):
Result.append(num)
print(f"The merge List_1 and List_2 = {Result}")
Result=List_1+List_2
print(f"without zero = {Result}")
# Tuple
"""Tuple :- Tuple is is sequence and immutable data type means when you store a data
we can't manupilate the data in python"""
my_tuple=(1,2,3,4,5,1,2,5)
print(type(my_tuple))
print(f"my_tuple data ={my_tuple}")
#Now we check the element using count in tuple
Count=my_tuple.count(5)
print(Count)
# Indexing
print(f"In my_tuple Indexing in zero indexing = {my_tuple[0]} element number located ")
#chek the element index
Index=my_tuple.index(4)
print(f"In tuple '4' element number of indexing = {Index}")
# example of immutable in tuple
#my_tuple[0]=100
#print(f"As you can see the data we not manuplilate show give bellow ={my_tuple}")
"""Making a list and print the element using for loop """
My_tup=(1,2,3,4,5)
for i in My_tup:
print(i)
# User inputs for start and end
usr_starte_tuple = int(input("Enter the element start = "))
usr_end_tuple = int(input("Enter the element end = "))
# Using a generator expression inside the tuple() constructor
# This is the standard way to "comprehend" a tuple
My_Tup = tuple(i for i in range(usr_starte_tuple, usr_end_tuple + 1))
# Printing the final tuple
print(f"Your Start and End elements stored in My_Tuple = {My_Tup}")
"""Make a Tuple by user start and end of ellement
using comprehension and print and check the ellement which was divisble 2 and 3"""
usr_starte_tuple = int(input("Enter the element start = "))
usr_end_tuple = int(input("Enter the element end = "))
My_Tup = tuple(i for i in range(usr_starte_tuple, usr_end_tuple + 1) if i % 2 ==0 and i % 3 ==0)
print(f"In the user end element are divisble by 2 and 3 is = {My_Tup}")
"""Now we make add the element value in tuple as we know that tuple is immutable?"""
Tup=(1,2,3,4,5)
print(f"first we have only 1 to 5 element only {Tup}")
# Conversion in tuple to list
My_List=list(Tup)
My_List.append(6)
Tup=tuple(My_List)
print(f"Now we have a 6 also using conversion {Tup}")
# String data type
"""String is a Sequence Immutable data type and it will ittrable also is called String """
# Example
Introduction="Hi my name is Masood Rahman and i am from New Delhi"
print(Introduction)
print(type(Introduction))
# Now we try to update
#Introduction[0]="M"
print(f"As you can see that we have a show a error {Introduction} that mean's this is Immutable")
# Now we check the Indexing
print(f" Check the in zero Indexing value = {Introduction[0]}\n")
# Now we used Itration
for j in Introduction:
print(f"{j}\n")
# Now we check Itrable
for i in range(0,len(Introduction)):
print(i, end=" ")
# Negative Indexing using Itrable
for i in range(len(Introduction)-1,-1,-1):
print(f"\n Negative Indexing = {i}")
# Different operation of a string
# add the two string
First_name="Masood "
print(First_name)
Laste_name="Rahman"
print(Laste_name)
full_name=First_name + Laste_name
print(f"we used concatenation = {full_name}")
# Multiply the operation in string
print(f"\n{First_name*2}")
"""ASCII Code:- we have comparision operation predine funcation ord()"""
name = "Masood"
for char in name:
print(f"{char}: {ord(char)}")
print("-----*****-----")
Name = "masood"
for Char in Name:
print(f"{Char}: {ord(Char)}")
# Comparison operation using ASCII
if name < Name:
# Lowercase letters have higher ASCII values than Uppercase
print(f"\n'{name}' is smaller because {name[0]} ({ord(name[0])}) < {Name[0]} = ({ord(Name[0])})")
elif name > Name:
print(f"\n'{name}' is larger because {name[0]} ({ord(name[0])}) > {Name[0]} = ({ord(Name[0])})")
else:
print(f"\n{name} = {Name} both are equal")
"""Make user end email id ASCII value check"""
email=input("Enter your valid email id = ").strip()
pattern = r"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$"
print(email)
for S_chr in email:
print(f"{S_chr}: {ord(S_chr)}")
"""Comparision betwen two user email id for ASCII value """
import re
Usr_1 = input("Enter 1st email id: ").strip()
Usr_2 = input("Enter 2nd email id: ").strip()
# Comparison logic
if Usr_1 < Usr_2:
print(f"\n'{Usr_1}' is < '{Usr_2}' based on ASCII order.")
elif Usr_1 > Usr_2:
print(f"\n'{Usr_1}' is > '{Usr_2}' based on ASCII order.")
else:
print(f"\nBoth email IDs are identical are equal.")
# To see specific ASCII values of the first characters:
print(f"ASCII of '{Usr_1[0]}': {ord(Usr_1[0])}")
print(f"ASCII of '{Usr_2[0]}': {ord(Usr_2[0])}")
# Slicing in String
introduction="Hi my name is Masood Rahman"
# right to left slicing idex
Slicing_Index=introduction[0:20]
print(Slicing_Index)
slicing_index=introduction[::-1]
print(f"{slicing_index}\n")
"""make user end string and check the palindrom or not """
my_string=input("Enter the word : ")
if my_string==my_string[::-1]:
print("Yes it's palindrome")
else:
print("No it's not palindrome")
# Sring Method
name = "masood rahman"
print(name)
capital=name.capitalize()
print(capital)
Title=name.title()
print(Title)
Upper=name.upper()
print(Upper)
Lower=name.lower()
print(Lower)
Swapcase=name.swapcase()
print(Swapcase)
# String Boolean Method
a=name.isupper()
print(f"All element are Capital later. __{a}__")
b=name.islower()
print(f"All element are small later. __{b}__")
c=name.istitle()
print(f"All element are Capital. __{c}__")
d=name.isalpha()
print(f"In this string have present space. __{d}__")
e=name.isalnum()
print(f"This string have only alphabet or number.___{e}__")
f=name.isspace()
print(f"This string have present space __{f}__")
intro="25"
print(intro,type(intro))
if intro.isdigit():
intro=int(intro)
print(f"They convert into string to integer :{intro,type(intro)}")
else:
("Not convert into integer ")
"""Make a string data type all elemenyt are small then convert into Capital """
Name="masood rahman"
up=Name.upper()
print(up)
"""Make a string and count the how many alphabet using ASCII """
Intro="Masood Rahman"
count=0
for chr in Intro:
ASCII=ord(chr)
# for small chr # for Cpital
if (ASCII>=65 and ASCII<=90) or (ASCII>=97 and ASCII<=122):
count=count+1
print(count)
"""Ask a string from user end. And count the
number of alphabet over there string using for loop itration"""
Usr=str(input("Write the Statement! "))
for char in Usr:
print(char)
count = 0
for char in Usr:
if char.isalpha():
count += 1
print("-----")
print(f"Total nunmber of alphabet count is = {count}")
"""Write the program from user end string data and check the number of UPPER() and LOWER()
"""
Usr=str(input("Enter the Statement! "))
Upp=0
Low=0
for chr in Usr:
print(chr)
if chr.isupper():
Upp+=1
print("---------")
print(f"Total Upper case = {Upp}")
for Chr in Usr:
print(Chr)
if Chr.islower():
Low+=1
print("--------")
print(f"Total Lower case = {Low}\n")
"""Ask from the user end as a string data and checkthe
the number of upper and lower case using ASCII condition"""
Usr=str(input("Enter the Statement! "))
Upp_count=0
Low_count=0
for chr in Usr:
ASCII=ord(chr)
if ASCII >= 65 and ASCII<=90:
Upp_count+=1
elif ASCII >= 97 and ASCII<=122:
Low_count+=1
print(f"ASCII Capital later = {Upp_count}")
print(f"ASCII Small later = {Low_count}\n")
"""Ask the user end string data type and convert into Upper case and Lower case"""
Usr=str(input("write the small str statement! "))
upp=""
for ch in Usr:
upp+=ch.upper()
print(f"usr statement '{Usr}' convert into --> {upp} captial later\n")
"""Ask the user end string data type and convert into Upper case and Lower case"""
Usr=str(input("write the capital str statement! "))
Low=""
for ch in Usr:
Low+=ch.lower()
print(f"usr statement '{Usr}' convert into --> {Low} captial later")
"""Ask the user end string data type convert upper case to lower case
and lower case to upper case condition """
Usr = input("Write the str statement! ")
swapped = ""
for ch in Usr:
if ch.isupper():
swapped += ch.lower() # Convert uppercase to lowercase
elif ch.islower():
swapped += ch.upper() # Convert lowercase to uppercase
else:
swapped += ch # Keep symbols/numbers as they are
print(f"Swapped string: {swapped}")
"""Write user end input and count a space"""
usr=str(input("write introduction : "))
space_count=0
for ch in usr:
if ch == " ":
space_count+=1
print(f"Total number of space = {space_count}")
# Topic Split and Join
"""In a string sequence data type split function used in to removed space"""
Intro="Hi my name is Masood Rahman and i am 25 year old"
print(Intro,type(Intro))
Split=Intro.split()
print(f"As you can see that the String data list using split()\n{Split}")
#"""problem no.1"""
Intro="Hi-my-name-is-Masood-Rahman-and-i-am-25-year-old"
Split_intro=Intro.split("-")
print(Split_intro)
print(f"The total length = {len(Intro)}")
""" In a string data type join funcation is used to convert into list to string"""
#Eexample
List=['Hi', 'my', 'name', 'is', 'Masood', 'Rahman', 'and', 'i', 'am', "25", 'year', 'old']
print(List,type(List))
Join_intro=" ".join(List)
print(f" As you can see that list convert into string = {Join_intro} and data type is {type(Join_intro)}")
# Drawback join () used only all element are str
List=['Hi', 'my', 'name', 'is', 'Masood', 'Rahman', 'and', 'i', 'am', 25, 'year', 'old']
Join_intro=" ".join(str (i) for i in List)
print(Join_intro,type(Join_intro))
"""Make a string to print in apposite direction
"""
Intro="Hi my name is Masood Rahman"
word=Intro.split()
word=word[::-1]
print(word)
"""Make a string in user end and print apposite direction"""
User=str(input("Tell me about your self : "))
Con_list=User.split()
Con_list=Con_list[::-1]
print(Con_list)
"""Make a user end string the first later of a word it should be caplital"""
User=str(input("Write anything in small later.. : "))
Cap=User.title()
print(Cap)
# String data type :- method->Count(), Replace(), Find(),Strip(), Endswith(),
python="python is a good programming language for the upcoming future"
Count=python.count("a")
print(f"The number of count of a--> is {Count}")
Check_word=python.startswith("python")
print(Check_word)
address=python.index("l")
print(address)
Replace=python.replace("p", "P")
print(Replace)
Intro="@@@@@@@Hi my name is Masood Rahman and i am from delhi@@@@@@@@"
print(Intro)
# this strip () used on whatsup, Ai chatbot,
removed = Intro.strip("@")
print(removed)
print("""--------------Sequence data type is complete-----------------------""")
# Maping Data Type:- Dictionary
"""An according to python programing language Dictionary mutable maping data type
is verry coman and verry verry used full in different Domain aspect
to build a logic.
like:-Ai,Ml,Data Analyst, Data Science, Django Developer, Cyber security
and etc.
"""
BMW={'Car_model':"BMW M5",
'Owner_name': "Masood Rahman",
'price':"1.5 cr",
'Insurance_Id': "DL12789BMW",
}
print(BMW,type(BMW))
print("---------*********------------\n")
# Get
My_dic={'Name':"Masood Rahman",
'Age':25,
'Gender':"Male",
'Phone no':7303367532}
print(My_dic)
print(f"Key-> value{My_dic["Name"]}\n")
print(f"{My_dic.get("DOB")}\n")
"""Make user end side Key is existing over the dic if yes then print the value
else value not found."""
My_info = {
'Name': "Masood Rahman",
'Gender': "Male",
'Age': 25,
'Phone no': 7303367532
}
# Condition to check the value
K_valu = input("Enter the Key: ")
result = My_info.get(K_valu)
if result is not None:
print(f"{result}\n")
else:
print(f"Key and value does not exist for: {K_valu}\n")
My_info = {
'Name': "Masood Rahman",
'Gender': "Male",
'Age': 25,
'Phone no': 7303367532
}
print(f"Curent Dictionary {My_info}\n")
# Add and Update () funcation
My_info.update({'Age':26,'Place':"New Delhi, India"})
print(f"Update Dictionary {My_info}\n")
# pop () funcation
My_info={'Name':"Masood Rahman",
'Gender':"Male",
'DOB':"8 May 2000",
'Phone no':7303367532,
'Place':"New Delhi India"}
print(My_info)
My_info.pop("Phone no")
print(My_info)
# Iterating Key Value Dictionary
my_info={'Name':"Masood Rahman",
'Gender':"Male",
'DOB':"8 May 2000",
'Phone no':7303367532,
'Place':"New Delhi India"}
#Keys () funcation
print(f"{my_info.keys()}\n")
"""Now we used Itration only for the key of dictionary """
for Key in my_info.keys():
print(Key)
#value () funcation
print(f"{my_info.values()}\n")
for Value in my_info.values():
print(Value)
"""Using Itrate to print dictionary keys and values using items() funcation"""
print("-------*********--------\nNow we apply itration using items() to print key ans value both")
for key, value in my_info.items():
print(f"{key} => {value}")
"""Make a two different list and convert into a dictionary as a key and value """
#1st List
Student_name=["Masood Rahman","Sonali Ratori", "Hritik Kumar", "Sumit Dang"]
#2nd List
Student_Class=["Science->Non Med","Comerces","Science-> Medical","Science->Non Med"]
disctionary={}
for i in range (0,len(Student_name)):
disctionary[Student_name[i]]=Student_Class[i]
for key, value in disctionary.items():
print(f"{key} => {value}")
print("\n--------******-------")
"""Ask from the user name class roll no all subject name and marks adding to a dictionary"""
Usr_name = input("Enter your Name: ")
Usr_class = input("Enter your class: ")
Usr_roll_no = str(int(input("Enter the roll no: ")))
Sub_name = {}
Subject_count = int(input("Enter how many subjects: "))
for _ in range(0, Subject_count):
name = input("Enter subject name: ")
marks = int(input(f"Enter marks for {name}: "))
# Add the name as a key and marks as the value to the dictionary
Sub_name[name] = marks
student_record = {
"Name": Usr_name,
"Class": Usr_class,
"Roll No": Usr_roll_no,
"Subjects": Sub_name
}
print("\nFinal Student Record:")
for key, value in student_record.items():
print(f"{key} => {value}")
"""Ask from the user name class roll no all subject name and marks adding to a dictionary
total marks, percentage and Divsion also """
Usr_name = input("Enter your Name: ")
Usr_class = input("Enter your class: ")
Usr_roll_no = str(int(input("Enter the roll no: ")))
Sub_name = {}
Subject_count = int(input("Enter how many subjects: "))
for _ in range(0, Subject_count):
name = input("Enter subject name: ")
marks = int(input(f"Enter marks for {name}: "))
# Add the name as a key and marks as the value to the dictionary
Sub_name[name] = marks
student_record = {
"Name": Usr_name,
"Class": Usr_class,
"Roll No": Usr_roll_no,
"Subjects": Sub_name
}
print("\nFinal Student Record:")
for key, value in student_record.items():
print(f"{key} => {value}")
total = 0
for marks_value in Sub_name.values():
total += marks_value
print(f"Total Marks: {total}")
max_marks = Subject_count * 100
percent = (total / max_marks) * 100
print(f"Percentage: {percent}%")
if percent <= 95:
print(f"Congratulation your {percent}% is count on first division")
elif percent>=85:
print(f"Congratulation your {percent}% is count on Seconnd division")
elif percent ==70:
print(f"Congratulation your {percent}% is count on third division")
elif percent ==50:
print(f"{percent} Pass")
else:
print(f"You are {percent}% fail ")
"""Ask a string data type from the uer end. to Display the dictionary where each key is a
a charectar and value is the frequance of that character that comes in that string
"""
Usr_str = input("write your statement: ")
freq = {} # 1. Name must match 'freq' used in the loop
for Chr in Usr_str:
if Chr in freq:
freq[Chr] += 1
else:
freq[Chr] = 1
print(freq)
for key, value in freq.items():
print(f"\n{key} => {value}")
"""given distionary to dictionary"""
Student_record = {
'Masood Rahman': {"Maths": 85, "Physics": 90, "Chemistry": 78, "Computer Science": 92, "English": 88},
'Hritik Kumar': {"Bio": 98, "Physics": 97, "Chemistry": 99, "Physical Education": 96, "English": 94},
'Jai Bhardwaj': {"Maths": 92, "Physics": 88, "Chemistry": 95, "Computer Science": 90, "English": 85},
'Pravesh Chauhan': {"Maths": 88, "Physics": 75, "Chemistry": 82, "Computer Science": 80, "English": 78}
}
for student, marks in Student_record.items():
print(f"\n{student} : {marks}")
total = sum(marks.values())
percent=total/500*100
#:.2f used to understand decimal upto two only
print(f"{student} Total Mark's: {total} and Percentage: {percent:.2f}%")
"""Now we check the Student if exsist in dictionary then print the value else student doen't exsist in user end"""
Student_record = {
'Masood Rahman': {"Maths": 85, "Physics": 90, "Chemistry": 78, "Computer Science": 92, "English": 88},
'Hritik Kumar': {"Bio": 98, "Physics": 97, "Chemistry": 99, "Physical Education": 96, "English": 94},
'Jai Bhardwaj': {"Maths": 92, "Physics": 88, "Chemistry": 95, "Computer Science": 90, "English": 85},
'Pravesh Chauhan': {"Maths": 88, "Physics": 75, "Chemistry": 82, "Computer Science": 80, "English": 78}
}
user_query = input("Enter the student name: ")