0% found this document useful (0 votes)
7 views147 pages

Vertopal

The document contains various Python programming examples, including basic arithmetic operations, conditional statements, and user input handling. It demonstrates how to perform tasks such as calculating sums, averages, and areas, as well as implementing control flow with if-else statements. Additionally, it covers topics like swapping variables, checking for leap years, and determining the largest or smallest of three numbers.

Uploaded by

cziww
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views147 pages

Vertopal

The document contains various Python programming examples, including basic arithmetic operations, conditional statements, and user input handling. It demonstrates how to perform tasks such as calculating sums, averages, and areas, as well as implementing control flow with if-else statements. Additionally, it covers topics like swapping variables, checking for leap years, and determining the largest or smallest of three numbers.

Uploaded by

cziww
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 147

print("Hello,World!

")

Hello,World!

print("Tiiwari Rushi")

print("Tiwari Rushi")

Tiwari Rushi

Program To Add Two Numbers


a=5
b=10
c=a+b
print(c)

15

a=10
b=20
c=a+b
print("Addiition Is",c)

Addiition Is 30

a=10
b=35
print(a+b,"Is Answer")

45 Is Answer

a=10
b=59
c=a+b
c
#popular mcq in exam, without print cmd output can be printed but only
in single VARIABLE

69

a=3.14
b==5.9
c=a+b
c
# == by mistake then compare, thus any garbage value is taken and is
always diffrent

62.14
a=3.14
b=5.9
c=a+b
c

9.040000000000001

Print Addn Subn Multiple And Div


a=6
b=2
print("addition is",a+b , "subtarction is", a-b, "multiplicatiion is",
a*b, "div is", a/b)

addition is 8 subtarction is 4 multiplicatiion is 12 div is 3.0

a=int(input("Enter 1st No:"))


b=int(input("Enter 2nd No:"))
c=a+b
print("Addition Is", c)
"""" general program , c= int(A)+int(b) ccan be used to convert string
to int"""

Enter 1st No:15


Enter 2nd No:15
Addition Is 30

a=int(input("Enter Marks Of MATHS:"))


b=int(input("Enter Marks Of SCIENCE:"))
c=int(input("Enter Marks Of ENGLISH:"))
d=a+b+c
print("TOTAL OUT OF 300 IS", d)

Enter Marks Of MATHS:69


Enter Marks Of SCIENCE:57
Enter Marks Of ENGLISH:89
TOTAL OUT OF 300 IS 215

a=int(input(" Marks Of MATHS:"))


b=int(input(" Marks Of SCIENCE:"))
c=int(input(" Marks Of ENGLISH:"))
d=a+b+c
print("TOTAL OUT OF 300 IS", d)
#program me avg mtlb result

Marks Of MATHS:89
Marks Of SCIENCE:68
Marks Of ENGLISH:85
TOTAL OUT OF 300 IS 242
<>:6: SyntaxWarning: 'str' object is not callable; perhaps you missed
a comma?
<>:6: SyntaxWarning: 'str' object is not callable; perhaps you missed
a comma?

Marks Of MATHS:80
Marks Of SCIENCE:

----------------------------------------------------------------------
-----
ValueError Traceback (most recent call
last)
~\AppData\Local\Temp/ipykernel_3456/1963627135.py in <module>
1 a=int(input(" Marks Of MATHS:"))
----> 2 b=int(input(" Marks Of SCIENCE:"))
3 c=int(input(" Marks Of ENGLISH:"))
4 d=a+b+c
5 print("TOTAL OUT OF 300 IS", d)

ValueError: invalid literal for int() with base 10: ''

a=int(input(" Marks Of MATHS:"))


b=int(input(" Marks Of SCIENCE:"))
c=int(input(" Marks Of ENGLISH:"))
d=a+b+c
print("TOTAL OUT OF 300 IS", d)
print("average=(a+b+c)/3")

Marks Of MATHS:80
Marks Of SCIENCE:880

a=int(input(" Marks Of MATHS:"))


b=int(input(" Marks Of SCIENCE:"))
c=int(input(" Marks Of ENGLISH:"))
d=a+b+c
print("TOTAL OUT OF 300 IS", d)
print("average=(a+b+c)/3")

a=int(input(" Marks Of MATHS:"))


b=int(input(" Marks Of SCIENCE:"))
c=int(input(" Marks Of ENGLISH:"))
d=a+b+c
print("TOTAL OUT OF 300 IS", d)
print("average=",(a+b+c)/3)
a=int(input(" Marks Of MATHS:"))
b=int(input(" Marks Of SCIENCE:"))
c=int(input(" Marks Of ENGLISH:"))
d=a+b+c
print("TOTAL OUT OF 300 IS", d)
print("average=",(a+b+c)/3)

Marks Of MATHS:100
Marks Of SCIENCE:100
Marks Of ENGLISH:100
TOTAL OUT OF 300 IS 300
average= 100.0

wat to print a program of area of triangle by


taking input from user
a=float(input("Enter base: "))
b=float(input("Enter Height: "))
area= 0.5*a*b
print("Area Of Triangle Is: " , area)
# "*" is fn for multiplication
# if not 0.5 then (1/2)*a*b

Enter base: 5
Enter Height: 10
Area Of Triangle Is: 25.0

area of circle
a=float(input("Enter The Radius: "))
area=3.14*a*a
print("Area Of Circle Is: ",area)

Enter The Radius: 1


Area Of Circle Is: 3.14

wap to convert c to f
c=float(input("Enter The Degree Celcius: "))
d=(9/5)*c+32
print("Fahrenheit Is: ", d)

#to ensure bodmas do ((9/5)*c)+32

Enter The Degree Celcius: 10


Fahrenheit Is: 50.0

wap to cnvrt f to c
f=float(input("Enter F: "))
c=(5/9)*(f-32)
print("Celcius Is: " ,c)

Enter F: 33
Celcius Is: 0.5555555555555556

f to c and c to f are tempraturre cnvrtr


a=float(input("Enter x: "))
b=float(input("Enter y: "))
print("Ans Is: ", a**b)

#pwr operator exclusive in python


#x^y hai

Enter x: 2
Enter y: 2
Ans Is: 4.0

w.a.p to print last digit of a given no


a=float(input("Enter No: "))
LastNo=a%10
print("Last No Of Digit Is: " ,LastNo)

# % is module operator anf gives remaindeeeer

Enter No: 155


Last No Of Digit Is: 5.0

a=float(input("Input No: "))


FirstDid=a//100
print("First Digit Is: " ,FirstDid)
"""" floor division -} gives the value by eliminating digit after
decimalpoint """

Input No: 891


First Digit Is: 8.0

wap to print 2nd dig of 3dig no


a=float(input("Number: "))
b=((a//10)%10)
print("2nd Digit Is: " ,b)

Number: 999
2nd Digit Is: 9.0

"""" 'CHEAT CODES'


1ST DIG ---- x//100
2nd dig ----(x//10)%10
3rd dig ---- x%10

for 4 dug no
1st -- x//1000
2nd -- (x//100)%10
3rd -- (x//10)%10
4th -- x%10

and so on
""""

que: wap to print sum of all dig of a 3dig no


a=int(input("number: "))
x=a//100
y=(a//10)%10
z=a%10
b=x+y+z
print("sum of all no: ",b)

number: 111
sum of all no: 3
que: wap for first and last dig sum of 4 dig no
a=int(input("4DIG NO: "))
x=a//1000
y=a%10
b=x+y
print("sum of 1st and last is: ",b)

4DIG NO: 5555


sum of 1st and last is: 10

que: sum of cube of all 3 dig of a 3 dig no


a=int(input("3dig no: "))
x=a//100
y=(a//10)%10
z=a%10
b=x+y+z
print("sum is: " ,x**3+y**3+z**3)

3dig no: 336


sum is: 270

wap to swap 2 nos USING 3RD variable


#asked in almost all languages
#ALWAYS DONE FROM RIGHT TO LEFT
a=int(input("enter 1st no: "))
b=int(input("enter 2nd no: "))
print("before swap: " ,a,b)
c=a
a=b
b=c
print("after swap: " ,a,b)

enter 1st no: 3


enter 2nd no: 5
before swap: 3 5
after swap: 5 3

wap to swap 2 nos WITHOUT using variable


a=int(input("enter 1st no: "))
b=int(input("enter 2nd no: "))
print("before swap: " ,a,b)
a=a+b
b=a-b
a=a-b
print("after swap: " ,a,b)

enter 1st no: 3


enter 2nd no: 5
before swap: 3 5
after swap: 5 3

a=int(input("enter 1st no: "))


b=int(input("enter 2nd no: "))
print("before swap: " ,a,b)
a=a*b
b=a//b
a=a//b
print("after swap: " ,a,b)

#mostly asked in exam without variable

enter 1st no: 3


enter 2nd no: 5
before swap: 3 5
after swap: 5 3

# arithmrtic operators of pythhon are 7 +-*% / // ** last two are


python exclusive thala for a reason baki me 5

# relational/comparision operator < <= > >= == != these


operaator are utilized with conditional statement

# conditional statement if if....else elif nested


if.....else

x=int(input("give a no:"))
if x==5 :
print("Hello")

give a no:5
Hello

x=int(input("give a no:"))
if x==5 :
print("Hello")
else:
print("Hi")

give a no:10
Hi
x=int(input("give a no:"))
if x>0 :
print("Positive")

give a no:1
Positive

x=int(input("give a no:"))
if x>0 :
print("Positive")
else:
print("Negative")

give a no:0
Negative

x=int(input("give a no:"))
if x>=0 :
print("Positive")
else:
print("Negative")

give a no:0
Positive

x=int(input("Enter No: "))


if x%2==0 :
print("NUMBER Is EVEN")
else:
print("NUMBER Is ODD")

#if no is divisible by 2 then its even hence x%2 fives remainder


which must 0 for even

Enter No: 3
NUMBER Is ODD

wap to print cube of no if its odd and square if


no is even
x=int(input("ENTER NO. :"))
if x%2==0 :
print("SQAUARE OF NO IS:",x*x)
else:
print("CUBE IS:" ,x*x*x)

ENTER NO. :2
SQAUARE OF NO IS: 4
x=int(input("give a no:"))
if x>0 :
print("Positive")
elif x<0:
print("Negative")
else:
print("Zero")

give a no:69
Positive

wap to make a menu driven calc for 4


mathematical operations(+-*/)
a=int(input("Enter 1st No: "))
b=int(input("Enter 2nd No: "))
print(''' Enter 1 For Addition,
Enter 2 For Subtraction,
Enter 3 For Multiplication,
And Enter 4 For Division''')
c=int(input("Enter Your Choice: "))
if c==1:
print("Addn Is: ",a+b)
elif c==2:
print("Subtraction Is: ", a-b)
elif c==3:
print("Multiplication Is: " ,a*b)
elif c==4:
print("Division Is: " ,a/b)
else:
print("Choice Is Invalid")
#multi line printing use 3 single quote

Enter 1st No: 22


Enter 2nd No: 22
' Enter 1 For Addition,
Enter 2 For Subtraction,
Enter 3 For Multiplication,
And Enter 4 For Division
Enter Your Choice: 1
Addn Is: 44
WAP TO PRINT CUBE OF A NUMBER IF IT IS
DIVISIBLE BY 5 AND SQUARE OF A NUMBER IF
IT IS DIVISIBLE BY 7 AND PRINT THE NUMBER
AS IT IS IF ISNT DIVISIBLE BY EITHER 5 OR 7
a=int(input("Enter A Number: "))
if a%5==0:
print("Cube Of No Is: " ,a**3)
elif a%7==0:
print("Square Of No Is: " ,a**2)
else:
print("The Given Number Is: " ,a)

Enter A Number: 35
Cube Of No Is: 42875

QUE: WAP TO MONTHS AND WEEKDAYS

LOGICAL OPERATORS
# "and" "or" are operators and "AND" "OR are opearations"

print result of student as mentionied below for


5 subjects(outta 100)
a=float(input("ENTER MARKS OF 1ST SUBJECT: "))
b=float(input("ENTER MARKS OF 2ND SUBJECT: "))
c=float(input("ENTER MARKS OF 3RD SUBJECT: "))
d=float(input("ENTER MARKS OF 4TH SUBJECT: "))
e=float(input("ENTER MARKS OF 5TH SUBJECT: "))
print("TOTAL OUT OF 500 IS", a+b+c+d+e)
print("avg" ,(a+b+c+d+e)/5)
avg=(a+b+c+d+e)/5
print("percentage is: ", avg)

if avg>=75 and avg<=100:


print("DISTINCTION")
elif avg>=60 and avg<=74:
print("FIRST CLASS")
elif avg>=45 and avg<=59:
print("SECOND CLASS")
elif avg>=35 and avg <=44:
print("PASS")
else:
print("FAIL")

ENTER MARKS OF 1ST SUBJECT: 33


ENTER MARKS OF 2ND SUBJECT: 33
ENTER MARKS OF 3RD SUBJECT: 33
ENTER MARKS OF 4TH SUBJECT: 33
ENTER MARKS OF 5TH SUBJECT: 33
TOTAL OUT OF 500 IS 165.0
avg 33.0
percentage is: 33.0
FAIL

wap to check given year is leap year or not


#every century year is not a leap year
#every 400th century is leap year
#not leap: 100,200,300,400.500.......
#leap year: 400,800,1200,1600,2000,2400....
#for noncentury year ---> divisible by 4 is leap year

x=int(input("ENTER YEAR TO CHECK THE LEAP YEAR: "))


if x%100==0 and x%400==0:
print("CENTURY YEAR IS A LEAP YEAR")
elif x%100!=0 and x%4==0 :
print("NON CENTURY YEAR IS LEAP YEAR")
else:
print("NOT A LEAP YEAR")

ENTER YEAR TO CHECK THE LEAP YEAR: 2026


NOT A LEAP YEAR

WAP TO FIND THE LARGEST MO OUT OF 3NO


(MAX/HIGHEST)
a=int(input("1ST NO: "))
b=int(input("2ND NO: "))
c=int(input("3RD NO: "))
b
if a> b and a>c:
print("A IS LARGEST")
elif b> a and b>c:
print("B IS LARGEST")
else:
print("C IS LARGEST")

1ST NO: 10
2ND NO: 2
3RD NO: 3
A IS LARGEST

a=int(input("1ST NO: "))


b=int(input("2ND NO: "))
c=int(input("3RD NO: "))

if a< b and a<c:


print("A IS SMALLEST")
elif b< a and b<c:
print("B IS SMALLEST")
else:
print("C IS SMALLEST")

1ST NO: 3
2ND NO: 2
3RD NO: 1
C IS SMALLEST

WAP TO CALC TAX ON GIVEN SALARY RANGE


a=int(input("ENTER YOUR SALARY: "))
if a>1 and a<700000:
print("TAX APPLIED IS 5%")
print("AMT. OF TAX TO BE PAID:" , a*(5/100))
elif a>700001 and a<1000000:
print("TAX APPLIED IS 15%")
print("AMT. OF TAX TO BE PAID:" , a*(15/100))
elif a>1000001 and a<1500000:
print("TAX APPLIED IS 20%")
print("AMT. OF TAX TO BE PAID:" , a*(20/100))
else:
print("TAX APPLIED IS 30%")
print("AMT. OF TAX TO BE PAID:" , a*(30/100))

ENTER YOUR SALARY: 1


TAX APPLIED IS 30%
AMT. OF TAX TO BE PAID: 0.3
wap to perform choice based task to find area 1
for circle, 2 for triangle, and 3for rectangle
otherwise invalid choice
print("TO FIND AREA OF CIRCLE CHOOSE 1")
print("TO FIND AREA OF TRIANGLE CHOOSE 2")
print("TO FIND AREA OF RECTANGLE CHOOSE 3")
c=int(input("ENTER YOUR CHOICE: "))

if c==1:
r=int(input("RADIUS IS: "))
print("AREA OF CIRCLE IS: " ,3.14*r*r)
elif c==2:
a=int(input("ALTITUDE IS: "))
b=int(input("BASE IS "))
print("AREA OF TRIANGLE IS: " ,(1/2)*a*b)
elif c==3:
l=int(input("LENGTH IS:" ))
m=int(input("BREADTH IS: "))
print("AREA OF RECTANGLE IS: " ,l*m)
else:
print("CHOICE IS INVALID")

TO FIND AREA OF CIRCLE CHOOSE 1


TO FIND AREA OF TRIANGLE CHOOSE 2
TO FIND AREA OF RECTANGLE CHOOSE 3
ENTER YOUR CHOICE: 5
CHOICE IS INVALID

1M QUE
x=float(input("TYPE NUMBER: "))
print(x)
print(type(x))

#kuch to error hai

TYPE NUMBER: 9
9.0
<class 'float'>

print("Hello" , end=" ")


print("Hi")

Hello Hi
print("Hello Hi")

Hello Hi

print("Hello" , end=" 123456789 ")


print("Hi")

Hello 123456789 Hi

print("Hello" , end="Shreya, ")


print("Hi Tiwari")

HelloShreya, Hi Tiwari

x=str(input("EnteR Your Name: "))


print("Hello;" ,x)

EnteR Your Name: USER


Hello; USER

#string --> is combination of multiple charcter including alphabet


digit symbol spave

x=str(input("EnteR Your Name: "))


print("Hello;" , x ,"Good Morning")

EnteR Your Name: USER


Hello; USER Good Morning

x=str(input("EnteR Your Name: "))


print("Hello;" , x ,",Good Morning!")

EnteR Your Name: abc


Hello; abc ,Good Morning!

LOOPING STATEMENT
1) while 2) for loop

x=1
while x<=1000:
print(x)
x=x+1

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

x=1000
while x>=1:
print(x)
x=x-1

1000
999
998
997
996
995
994
993
992
991
990
989
988
987
986
985
984
983
982
981
980
979
978
977
976
975
974
973
972
971
970
969
968
967
966
965
964
963
962
961
960
959
958
957
956
955
954
953
952
951
950
949
948
947
946
945
944
943
942
941
940
939
938
937
936
935
934
933
932
931
930
929
928
927
926
925
924
923
922
921
920
919
918
917
916
915
914
913
912
911
910
909
908
907
906
905
904
903
902
901
900
899
898
897
896
895
894
893
892
891
890
889
888
887
886
885
884
883
882
881
880
879
878
877
876
875
874
873
872
871
870
869
868
867
866
865
864
863
862
861
860
859
858
857
856
855
854
853
852
851
850
849
848
847
846
845
844
843
842
841
840
839
838
837
836
835
834
833
832
831
830
829
828
827
826
825
824
823
822
821
820
819
818
817
816
815
814
813
812
811
810
809
808
807
806
805
804
803
802
801
800
799
798
797
796
795
794
793
792
791
790
789
788
787
786
785
784
783
782
781
780
779
778
777
776
775
774
773
772
771
770
769
768
767
766
765
764
763
762
761
760
759
758
757
756
755
754
753
752
751
750
749
748
747
746
745
744
743
742
741
740
739
738
737
736
735
734
733
732
731
730
729
728
727
726
725
724
723
722
721
720
719
718
717
716
715
714
713
712
711
710
709
708
707
706
705
704
703
702
701
700
699
698
697
696
695
694
693
692
691
690
689
688
687
686
685
684
683
682
681
680
679
678
677
676
675
674
673
672
671
670
669
668
667
666
665
664
663
662
661
660
659
658
657
656
655
654
653
652
651
650
649
648
647
646
645
644
643
642
641
640
639
638
637
636
635
634
633
632
631
630
629
628
627
626
625
624
623
622
621
620
619
618
617
616
615
614
613
612
611
610
609
608
607
606
605
604
603
602
601
600
599
598
597
596
595
594
593
592
591
590
589
588
587
586
585
584
583
582
581
580
579
578
577
576
575
574
573
572
571
570
569
568
567
566
565
564
563
562
561
560
559
558
557
556
555
554
553
552
551
550
549
548
547
546
545
544
543
542
541
540
539
538
537
536
535
534
533
532
531
530
529
528
527
526
525
524
523
522
521
520
519
518
517
516
515
514
513
512
511
510
509
508
507
506
505
504
503
502
501
500
499
498
497
496
495
494
493
492
491
490
489
488
487
486
485
484
483
482
481
480
479
478
477
476
475
474
473
472
471
470
469
468
467
466
465
464
463
462
461
460
459
458
457
456
455
454
453
452
451
450
449
448
447
446
445
444
443
442
441
440
439
438
437
436
435
434
433
432
431
430
429
428
427
426
425
424
423
422
421
420
419
418
417
416
415
414
413
412
411
410
409
408
407
406
405
404
403
402
401
400
399
398
397
396
395
394
393
392
391
390
389
388
387
386
385
384
383
382
381
380
379
378
377
376
375
374
373
372
371
370
369
368
367
366
365
364
363
362
361
360
359
358
357
356
355
354
353
352
351
350
349
348
347
346
345
344
343
342
341
340
339
338
337
336
335
334
333
332
331
330
329
328
327
326
325
324
323
322
321
320
319
318
317
316
315
314
313
312
311
310
309
308
307
306
305
304
303
302
301
300
299
298
297
296
295
294
293
292
291
290
289
288
287
286
285
284
283
282
281
280
279
278
277
276
275
274
273
272
271
270
269
268
267
266
265
264
263
262
261
260
259
258
257
256
255
254
253
252
251
250
249
248
247
246
245
244
243
242
241
240
239
238
237
236
235
234
233
232
231
230
229
228
227
226
225
224
223
222
221
220
219
218
217
216
215
214
213
212
211
210
209
208
207
206
205
204
203
202
201
200
199
198
197
196
195
194
193
192
191
190
189
188
187
186
185
184
183
182
181
180
179
178
177
176
175
174
173
172
171
170
169
168
167
166
165
164
163
162
161
160
159
158
157
156
155
154
153
152
151
150
149
148
147
146
145
144
143
142
141
140
139
138
137
136
135
134
133
132
131
130
129
128
127
126
125
124
123
122
121
120
119
118
117
116
115
114
113
112
111
110
109
108
107
106
105
104
103
102
101
100
99
98
97
96
95
94
93
92
91
90
89
88
87
86
85
84
83
82
81
80
79
78
77
76
75
74
73
72
71
70
69
68
67
66
65
64
63
62
61
60
59
58
57
56
55
54
53
52
51
50
49
48
47
46
45
44
43
42
41
40
39
38
37
36
35
34
33
32
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1

x=0
while x<=999:
print(x)
x=x+3
# x+=1

0
3
6
9
12
15
18
21
24
27
30
33
36
39
42
45
48
51
54
57
60
63
66
69
72
75
78
81
84
87
90
93
96
99
102
105
108
111
114
117
120
123
126
129
132
135
138
141
144
147
150
153
156
159
162
165
168
171
174
177
180
183
186
189
192
195
198
201
204
207
210
213
216
219
222
225
228
231
234
237
240
243
246
249
252
255
258
261
264
267
270
273
276
279
282
285
288
291
294
297
300
303
306
309
312
315
318
321
324
327
330
333
336
339
342
345
348
351
354
357
360
363
366
369
372
375
378
381
384
387
390
393
396
399
402
405
408
411
414
417
420
423
426
429
432
435
438
441
444
447
450
453
456
459
462
465
468
471
474
477
480
483
486
489
492
495
498
501
504
507
510
513
516
519
522
525
528
531
534
537
540
543
546
549
552
555
558
561
564
567
570
573
576
579
582
585
588
591
594
597
600
603
606
609
612
615
618
621
624
627
630
633
636
639
642
645
648
651
654
657
660
663
666
669
672
675
678
681
684
687
690
693
696
699
702
705
708
711
714
717
720
723
726
729
732
735
738
741
744
747
750
753
756
759
762
765
768
771
774
777
780
783
786
789
792
795
798
801
804
807
810
813
816
819
822
825
828
831
834
837
840
843
846
849
852
855
858
861
864
867
870
873
876
879
882
885
888
891
894
897
900
903
906
909
912
915
918
921
924
927
930
933
936
939
942
945
948
951
954
957
960
963
966
969
972
975
978
981
984
987
990
993
996
999

print("Hello World")

Hello World

x=1
while x<=1000:
print(x , end= " ")
x=x+1

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

x=1
while x<=1000:
print(x , end= " + ")
x=x+1

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 +

x=0
while x<=1000:
print(x)
x=x+3
# x+=1

0
3
6
9
12
15
18
21
24
27
30
33
36
39
42
45
48
51
54
57
60
63
66
69
72
75
78
81
84
87
90
93
96
99
102
105
108
111
114
117
120
123
126
129
132
135
138
141
144
147
150
153
156
159
162
165
168
171
174
177
180
183
186
189
192
195
198
201
204
207
210
213
216
219
222
225
228
231
234
237
240
243
246
249
252
255
258
261
264
267
270
273
276
279
282
285
288
291
294
297
300
303
306
309
312
315
318
321
324
327
330
333
336
339
342
345
348
351
354
357
360
363
366
369
372
375
378
381
384
387
390
393
396
399
402
405
408
411
414
417
420
423
426
429
432
435
438
441
444
447
450
453
456
459
462
465
468
471
474
477
480
483
486
489
492
495
498
501
504
507
510
513
516
519
522
525
528
531
534
537
540
543
546
549
552
555
558
561
564
567
570
573
576
579
582
585
588
591
594
597
600
603
606
609
612
615
618
621
624
627
630
633
636
639
642
645
648
651
654
657
660
663
666
669
672
675
678
681
684
687
690
693
696
699
702
705
708
711
714
717
720
723
726
729
732
735
738
741
744
747
750
753
756
759
762
765
768
771
774
777
780
783
786
789
792
795
798
801
804
807
810
813
816
819
822
825
828
831
834
837
840
843
846
849
852
855
858
861
864
867
870
873
876
879
882
885
888
891
894
897
900
903
906
909
912
915
918
921
924
927
930
933
936
939
942
945
948
951
954
957
960
963
966
969
972
975
978
981
984
987
990
993
996
999

x=0
while x<=1000:
print(x)
x=x+2
# x+=2
0
2
4
6
8
10
12
14
16
18
20
22
24
26
28
30
32
34
36
38
40
42
44
46
48
50
52
54
56
58
60
62
64
66
68
70
72
74
76
78
80
82
84
86
88
90
92
94
96
98
100
102
104
106
108
110
112
114
116
118
120
122
124
126
128
130
132
134
136
138
140
142
144
146
148
150
152
154
156
158
160
162
164
166
168
170
172
174
176
178
180
182
184
186
188
190
192
194
196
198
200
202
204
206
208
210
212
214
216
218
220
222
224
226
228
230
232
234
236
238
240
242
244
246
248
250
252
254
256
258
260
262
264
266
268
270
272
274
276
278
280
282
284
286
288
290
292
294
296
298
300
302
304
306
308
310
312
314
316
318
320
322
324
326
328
330
332
334
336
338
340
342
344
346
348
350
352
354
356
358
360
362
364
366
368
370
372
374
376
378
380
382
384
386
388
390
392
394
396
398
400
402
404
406
408
410
412
414
416
418
420
422
424
426
428
430
432
434
436
438
440
442
444
446
448
450
452
454
456
458
460
462
464
466
468
470
472
474
476
478
480
482
484
486
488
490
492
494
496
498
500
502
504
506
508
510
512
514
516
518
520
522
524
526
528
530
532
534
536
538
540
542
544
546
548
550
552
554
556
558
560
562
564
566
568
570
572
574
576
578
580
582
584
586
588
590
592
594
596
598
600
602
604
606
608
610
612
614
616
618
620
622
624
626
628
630
632
634
636
638
640
642
644
646
648
650
652
654
656
658
660
662
664
666
668
670
672
674
676
678
680
682
684
686
688
690
692
694
696
698
700
702
704
706
708
710
712
714
716
718
720
722
724
726
728
730
732
734
736
738
740
742
744
746
748
750
752
754
756
758
760
762
764
766
768
770
772
774
776
778
780
782
784
786
788
790
792
794
796
798
800
802
804
806
808
810
812
814
816
818
820
822
824
826
828
830
832
834
836
838
840
842
844
846
848
850
852
854
856
858
860
862
864
866
868
870
872
874
876
878
880
882
884
886
888
890
892
894
896
898
900
902
904
906
908
910
912
914
916
918
920
922
924
926
928
930
932
934
936
938
940
942
944
946
948
950
952
954
956
958
960
962
964
966
968
970
972
974
976
978
980
982
984
986
988
990
992
994
996
998
1000

x=7
while x<=71:
print(x , end= " , ")
x=x+7

''''x=7
while x<=10:
print(7*x)
x=x+1 ''''

7 , 14 , 21 , 28 , 35 , 42 , 49 , 56 , 63 , 70 ,

x=5
while x<=31:
print(x , end= " , ")
x=x+5

5 , 10 , 15 , 20 , 25 , 30 ,

x=1

while x<9:
print(y, end= " , ")

1 , 4 , 9 , 16 , 25 , 36 , 49 , 64 ,

wap to print series 1 to n


n=int(input("Enter Ending No: "))
x=1
while x<=n:
print(x
x=x+1

Enter Ending No: 666


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

x=int(input("Enter Starting No: "))


n=int(input("Enter Ending No: "))
while x<=n:
print(x)
x=x+1

Enter Starting No: 1


Enter Ending No: 5
1
2
3
4
5

print series xto y or n

wap to print multiples of 9 in range 1 to 5000


x=9
while x<=5000:
print(x)
x=x+9

9
18
27
36
45
54
63
72
81
90
99
108
117
126
135
144
153
162
171
180
189
198
207
216
225
234
243
252
261
270
279
288
297
306
315
324
333
342
351
360
369
378
387
396
405
414
423
432
441
450
459
468
477
486
495
504
513
522
531
540
549
558
567
576
585
594
603
612
621
630
639
648
657
666
675
684
693
702
711
720
729
738
747
756
765
774
783
792
801
810
819
828
837
846
855
864
873
882
891
900
909
918
927
936
945
954
963
972
981
990
999
1008
1017
1026
1035
1044
1053
1062
1071
1080
1089
1098
1107
1116
1125
1134
1143
1152
1161
1170
1179
1188
1197
1206
1215
1224
1233
1242
1251
1260
1269
1278
1287
1296
1305
1314
1323
1332
1341
1350
1359
1368
1377
1386
1395
1404
1413
1422
1431
1440
1449
1458
1467
1476
1485
1494
1503
1512
1521
1530
1539
1548
1557
1566
1575
1584
1593
1602
1611
1620
1629
1638
1647
1656
1665
1674
1683
1692
1701
1710
1719
1728
1737
1746
1755
1764
1773
1782
1791
1800
1809
1818
1827
1836
1845
1854
1863
1872
1881
1890
1899
1908
1917
1926
1935
1944
1953
1962
1971
1980
1989
1998
2007
2016
2025
2034
2043
2052
2061
2070
2079
2088
2097
2106
2115
2124
2133
2142
2151
2160
2169
2178
2187
2196
2205
2214
2223
2232
2241
2250
2259
2268
2277
2286
2295
2304
2313
2322
2331
2340
2349
2358
2367
2376
2385
2394
2403
2412
2421
2430
2439
2448
2457
2466
2475
2484
2493
2502
2511
2520
2529
2538
2547
2556
2565
2574
2583
2592
2601
2610
2619
2628
2637
2646
2655
2664
2673
2682
2691
2700
2709
2718
2727
2736
2745
2754
2763
2772
2781
2790
2799
2808
2817
2826
2835
2844
2853
2862
2871
2880
2889
2898
2907
2916
2925
2934
2943
2952
2961
2970
2979
2988
2997
3006
3015
3024
3033
3042
3051
3060
3069
3078
3087
3096
3105
3114
3123
3132
3141
3150
3159
3168
3177
3186
3195
3204
3213
3222
3231
3240
3249
3258
3267
3276
3285
3294
3303
3312
3321
3330
3339
3348
3357
3366
3375
3384
3393
3402
3411
3420
3429
3438
3447
3456
3465
3474
3483
3492
3501
3510
3519
3528
3537
3546
3555
3564
3573
3582
3591
3600
3609
3618
3627
3636
3645
3654
3663
3672
3681
3690
3699
3708
3717
3726
3735
3744
3753
3762
3771
3780
3789
3798
3807
3816
3825
3834
3843
3852
3861
3870
3879
3888
3897
3906
3915
3924
3933
3942
3951
3960
3969
3978
3987
3996
4005
4014
4023
4032
4041
4050
4059
4068
4077
4086
4095
4104
4113
4122
4131
4140
4149
4158
4167
4176
4185
4194
4203
4212
4221
4230
4239
4248
4257
4266
4275
4284
4293
4302
4311
4320
4329
4338
4347
4356
4365
4374
4383
4392
4401
4410
4419
4428
4437
4446
4455
4464
4473
4482
4491
4500
4509
4518
4527
4536
4545
4554
4563
4572
4581
4590
4599
4608
4617
4626
4635
4644
4653
4662
4671
4680
4689
4698
4707
4716
4725
4734
4743
4752
4761
4770
4779
4788
4797
4806
4815
4824
4833
4842
4851
4860
4869
4878
4887
4896
4905
4914
4923
4932
4941
4950
4959
4968
4977
4986
4995

x=1
while x<=5000:
if x%9==0:
print(x)
x=x+1

9
18
27
36
45
54
63
72
81
90
99
108
117
126
135
144
153
162
171
180
189
198
207
216
225
234
243
252
261
270
279
288
297
306
315
324
333
342
351
360
369
378
387
396
405
414
423
432
441
450
459
468
477
486
495
504
513
522
531
540
549
558
567
576
585
594
603
612
621
630
639
648
657
666
675
684
693
702
711
720
729
738
747
756
765
774
783
792
801
810
819
828
837
846
855
864
873
882
891
900
909
918
927
936
945
954
963
972
981
990
999
1008
1017
1026
1035
1044
1053
1062
1071
1080
1089
1098
1107
1116
1125
1134
1143
1152
1161
1170
1179
1188
1197
1206
1215
1224
1233
1242
1251
1260
1269
1278
1287
1296
1305
1314
1323
1332
1341
1350
1359
1368
1377
1386
1395
1404
1413
1422
1431
1440
1449
1458
1467
1476
1485
1494
1503
1512
1521
1530
1539
1548
1557
1566
1575
1584
1593
1602
1611
1620
1629
1638
1647
1656
1665
1674
1683
1692
1701
1710
1719
1728
1737
1746
1755
1764
1773
1782
1791
1800
1809
1818
1827
1836
1845
1854
1863
1872
1881
1890
1899
1908
1917
1926
1935
1944
1953
1962
1971
1980
1989
1998
2007
2016
2025
2034
2043
2052
2061
2070
2079
2088
2097
2106
2115
2124
2133
2142
2151
2160
2169
2178
2187
2196
2205
2214
2223
2232
2241
2250
2259
2268
2277
2286
2295
2304
2313
2322
2331
2340
2349
2358
2367
2376
2385
2394
2403
2412
2421
2430
2439
2448
2457
2466
2475
2484
2493
2502
2511
2520
2529
2538
2547
2556
2565
2574
2583
2592
2601
2610
2619
2628
2637
2646
2655
2664
2673
2682
2691
2700
2709
2718
2727
2736
2745
2754
2763
2772
2781
2790
2799
2808
2817
2826
2835
2844
2853
2862
2871
2880
2889
2898
2907
2916
2925
2934
2943
2952
2961
2970
2979
2988
2997
3006
3015
3024
3033
3042
3051
3060
3069
3078
3087
3096
3105
3114
3123
3132
3141
3150
3159
3168
3177
3186
3195
3204
3213
3222
3231
3240
3249
3258
3267
3276
3285
3294
3303
3312
3321
3330
3339
3348
3357
3366
3375
3384
3393
3402
3411
3420
3429
3438
3447
3456
3465
3474
3483
3492
3501
3510
3519
3528
3537
3546
3555
3564
3573
3582
3591
3600
3609
3618
3627
3636
3645
3654
3663
3672
3681
3690
3699
3708
3717
3726
3735
3744
3753
3762
3771
3780
3789
3798
3807
3816
3825
3834
3843
3852
3861
3870
3879
3888
3897
3906
3915
3924
3933
3942
3951
3960
3969
3978
3987
3996
4005
4014
4023
4032
4041
4050
4059
4068
4077
4086
4095
4104
4113
4122
4131
4140
4149
4158
4167
4176
4185
4194
4203
4212
4221
4230
4239
4248
4257
4266
4275
4284
4293
4302
4311
4320
4329
4338
4347
4356
4365
4374
4383
4392
4401
4410
4419
4428
4437
4446
4455
4464
4473
4482
4491
4500
4509
4518
4527
4536
4545
4554
4563
4572
4581
4590
4599
4608
4617
4626
4635
4644
4653
4662
4671
4680
4689
4698
4707
4716
4725
4734
4743
4752
4761
4770
4779
4788
4797
4806
4815
4824
4833
4842
4851
4860
4869
4878
4887
4896
4905
4914
4923
4932
4941
4950
4959
4968
4977
4986
4995

wap to print sum of 1st n nos/ EVALUATE


1+2+3+.....+N
n=int(input("Enter Ending No: "))
x=1
sum=0
while x<=n:
sum=sum+x
x=x+1
print(sum)
Enter Ending No: 3
6

n=int(input("Enter Ending No: "))


x=1
sum=0
while x<=n:
sum=sum+x
x=x+1
print(sum)

Enter Ending No: 3


1
3
6

n=int(input("Enter Ending No: "))


x=1
sum=0
while x<=n:
sum=sum+x
x=x+1
print(sum, end= " , ")

Enter Ending No: 10


1 , 3 , 6 , 10 , 15 , 21 , 28 , 36 , 45 , 55 ,

wap to print sum of squares of 1st n nos/


EVALUATE 1^2+2^2+3^2+.....+N^2
n=int(input("Enter Ending No: "))
x=1
sum=0
while x<=n:
sum=sum+(x**2)
x=x+1
print(sum)

Enter Ending No: 2


5

n=int(input("Enter Ending No: "))


x=1
sum=0
while x<=n:
sum=sum+(x**3)
x=x+1
print(sum)

Enter Ending No: 2


9

EVALUATE 1^3+2^3+3^3+.....+N^3

1+1/2+..+1/n
n=int(input("Enter Ending No: "))
x=1
sum=0
while x<=n:
sum=sum+(1/x)
x=x+1
print(sum)

Enter Ending No: 1000000


14.392726722864989

wap to calc multiplication of 1st n nos/


EVALUATE 123..*N
n=int(input("Enter Ending No: "))
x=1
m=1
while x<=n:
m=m*x
x=x+1
print(m)

# OR find factorial of a no.

Enter Ending No: 5


120
wap to count length of a no
x=input("enter no: ")
print("Entered No Is: ", x)
print(len(x) , "are digits of given no.")

enter no: 5555


Entered No Is: 5555
4 are digits of given no.

x=int(input("enter no: "))


print("Entered No Is: ", x)
c=0
while x!=0 :
x=x//10
c=c+1
print( c , "are digits of given no.")

enter no: 10
Entered No Is: 10
2 are digits of given no.

# wap to count length of a no if its odd thnen


print square of a no. anf if its eventhen print
cube of no
x=int(input("enter no: "))
y=x
print("Entered No Is: ", x)
c=0
while x!=0 :
x=x//10
c=c+1
print( c , "are digits of given no.")
if c%2!=0 :
print("Cube Of No Is: ", y**3)
else:
print("Square Of No Is: ", y**2)

enter no: 2
Entered No Is: 2
1 are digits of given no.
Cube Of No Is: 8
wap to print all factors of a no
n=int(input("Enter No: "))
i=1
while i<=n:
if n%i==0:
print(i)
i=i+1

Enter No: 11
1
11

n=int(input("Enter No: "))


i=1
while i<=n:
if n%i==0:
print(i)
i=i+1

Enter No: 4
1
2

wap to print all factor of no and count them


n=int(input("Enter No: "))
c=0
i=1
while i<=n:
if n%i==0:
print(i)
c=c+1
i=i+1
print("No. Of Factors Of Number Are: ", c)

Enter No: 10
1
2
5
10
No. Of Factors Of Number Are: 4

wap to check wether given no is prime or not


n=int(input("Enter No: "))
c=0
i=1
while i<=n:
if n%i==0:
print(i)
c=c+1
i=i+1
print("No. Of Factors Of Number Are: ", c)
if c==2:
print("Number Is Prime")
else:
print("Number Is Not Prime")

#MOST IMP HAI

Enter No: -7
No. Of Factors Of Number Are: 0
Number Is Not Prime

wap to check wether given 3 dig no is


armstrong or not
x=int(input("Enter 3 Dig No: "))
a=x//100
b=((x//10)%10)
c=x%10
print("Sum Is: ",a**3+b**3+c**3)
d=a**3+b**3+c**3
if d==x :
print("Armstrong")
else:
print("Not Armstrong")

#there are three 3 dig no which are armstrong 153 370 371

Enter 3 Dig No: 153


Sum Is: 153
Armstrong

wap to reverse a given no


x=int(input("Enter No:"))
rev=0
while x!=0:
d=x%10
rev=(rev*10)+d
x=x//10
print("Reverse Of No Is: ", rev)

Enter No:1020
Reverse Of No Is: 201

#1%10=1
#1//10=0

wap to chech given no is palindrome or not


x=int(input("Enter No:"))
y=x
rev=0
while x!=0:
d=x%10
rev=(rev*10)+d
x=x//10
print("Reverse Of No Is: ", rev)
if y==rev:
print("GIVEN NO IS PALINDROME")
else:
print("GIVEN NO IS NOT A PALINDROME")

Enter No:313
Reverse Of No Is: 313
GIVEN NO IS PALINDROME

#direct x variablle compare na karvu kemke chelle toh x zero thay che
etle x ne ek temporary value ma store kari levy

wap to print fibonacci serier of n terms


n=int(input("Enter No Term: "))
a=0
b=1
print(a)
print(b)
x=3
while x<=n: #or if x=1 while x<=(n-2)
sum=a+b
print(sum)
a=b
b=sum
x=x+1

Enter No Term: 7
0
1
1
2
3
5
8

n=int(input("Enter No Term: "))


a=0
b=1
print(a)
print(b)
x=3
while x<=n:
sum=a+b
print(sum , end= " ")
a=b
b=sum
x=x+1

Enter No Term: 7
0
1
1 2 3 5 8

for loop
for x in range(1, 11, 1):
print(x)

1
2
3
4
5
6
7
8
9
10

for x in range(1, 11, 1):


print(x, end= " ")
1 2 3 4 5 6 7 8 9 10

for x in range(10, 0, -1):


print(x)

10
9
8
7
6
5
4
3
2
1

for x in range(10, 0, -2):


print(x)

10
8
6
4
2

for x in range(2, 21, 2):


print(x)

2
4
6
8
10
12
14
16
18
20

for x in range(1, 51, 2):


print(x)

1
3
5
7
9
11
13
15
17
19
21
23
25
27
29
31
33
35
37
39
41
43
45
47
49

for x in range(10):
print(x)
#by default initializaation of range fn is 0

0
1
2
3
4
5
6
7
8
9

for x in range(1,10):
print(x)
#increase decrease na lia hoto bhi +1 hi hoga

1
2
3
4
5
6
7
8
9

for x in range(10,1,-1):
print(x)

10
9
8
7
6
5
4
3
2

for x in range(10,1):
print(x)
#error dega -1 nahi samjega voh

n=int(input("Enter A No: "))


for x in range (1, n+1 ,1):
print(x)

Enter A No: 5
1
2
3
4
5

n=int(input("Enter A No: "))


for x in range (1, n+1 ,1):
print(x, end= " ")

Enter A No: 10
1 2 3 4 5 6 7 8 9 10

m=int(input("Enter Initialization: "))


n=int(input("Enter A No: "))
for x in range (m, n+1 ,1):
print(x)

Enter Initialization: 1
Enter A No: 10
1
2
3
4
5
6
7
8
9
10
wap to print sum of first n/ EVALUATE 1+2+3+....
+N
n=int(input("Enter A No: "))
sum=0
for x in range (1, n+1, 1):
sum=sum+x
print(sum)

Enter A No: 8
36

n=int(input("Enter A No: "))


f=1
for x in range( 1, n+1, 1):
f=f*x
print(f)

Enter A No: 5
120

palindrome primeno armstrong 10M Hai

pattern programming
#possiblepatterns: 1)square pattern
# 2)triangle pattern
# 3) pyramid pattern
# 4) diamodpattern

n=int(input("Enter N:"))
for x in range (1,n+1,1): #row
for y in range(1,n+1,1): #column
print("*" ,end=" ")
print(" ")
#nested for loop

Enter N:5
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *

#if external loop runs n times internal lloop runs n*n times

n=int(input("Enter N:"))
for x in range (1,n+1,1):
for y in range(1,n+1,1):
print(x ,end=" ")
print(" ")

Enter N:3
1 1 1
2 2 2
3 3 3

n=int(input("Enter N:"))
for i in range (1,n+1,1):
for j in range(1,n+1,1):
print(j ,end=" ")
print(" ")

Enter N:3
1 2 3
1 2 3
1 2 3

n=int(input("Enter N:"))
for i in range (1,n+1,1):
for j in range(1,n+1,1):
print(i%2 ,end=" ")
print(" ")

Enter N:4
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0

n=int(input("Enter N:"))
for i in range (1,n+1,1):
for j in range(1,n+1,1):
print(j%2 ,end=" ")
print(" ")

Enter N:4
1 0 1 0
1 0 1 0
1 0 1 0
1 0 1 0

n=int(input("Enter N:"))
for i in range (1,n+1,1):
for j in range(1,i+1,1):
print("*" ,end=" ")
print(" ")
Enter N:3
*
* *
* * *

n=int(input("Enter N:"))
for i in range (1,n+1,1):
for j in range(1,i+1,1):
print(j ,end=" ")
print(" ")

Enter N:5
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

n=int(input("Enter N:"))
for i in range (1,n+1,1):
for j in range(1,i+1,1):
print(i ,end=" ")
print(" ")

Enter N:5
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5

n=int(input("Enter N:"))
for i in range (1,n+1,1):
for j in range(i,n+1,1):
print(i ,end=" ")
print(" ")

Enter N:9
1 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2
3 3 3 3 3 3 3
4 4 4 4 4 4
5 5 5 5 5
6 6 6 6
7 7 7
8 8
9

n=int(input("Enter N:"))
for i in range (1,n+1,1):
for j in range(n, i-1, -1):
print(i ,end=" ")
print(" ")

Enter N:2
1 1
2

n=int(input("Enter N:"))
for i in range (1,n+1,1):
for j in range(1,i+1,1):
print(i+j-1 ,end=" ")
print(" ")

Enter N:3
1
2 3
3 4 5

n=int(input("Enter N:"))
for i in range (1,n+1,1):
for j in range(1,i+1,1):
print((2*i)-1 ,end=" ")
print(" ")

Enter N:5
1
3 3
5 5 5
7 7 7 7
9 9 9 9 9

n=int(input("Enter N:"))
for i in range (n, 0, -1):
for j in range(1,i+1,1):
print(i ,end=" ")
print(" ")

Enter N:5
5 5 5 5 5
4 4 4 4
3 3 3
2 2
1

n=int(input("Enter N:"))
for i in range (1, n+1, 1):
for j in range(n, i-1, -1):
print(j ,end=" ")
print(" ")
Enter N:4
4 3 2 1
4 3 2
4 3
4

x=3e4
print(type(x))

<class 'float'>

n=int(input("Enter N:"))
k=1
for i in range (1,n+1,1):
for j in range(1,i+1,1):
print(k ,end=" ")
k=k+1
print(" ")

#can say imp haii

Enter N:5
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15

n=int(input("Enter N:"))
for i in range (n, 0, -1):
for j in range(i, 0, -1):
print(j ,end=" ")
print(" ")

Enter N:5
5 4 3 2 1
4 3 2 1
3 2 1
2 1
1

n=int(input("Enter N:"))
for i in range (1, n+1, 1):
for j in range(1,i+1,1):
print(i*i ,end=" ")
print(" ")

Enter N:4
1
4 4
9 9 9
16 16 16 16

n=int(input("Enter N:"))
for i in range (1, n+1, 1):
for j in range(1,i+1,1):
print((i*i)-1 ,end=" ")
print(" ")

Enter N:5
0
3 3
8 8 8
15 15 15 15
24 24 24 24 24

x='A'
print(ord(x))

65

x=65
print(chr(x))

#mcq ord and chr method for ascii

n=int(input("Enter N:"))
for i in range (1,n+1,1):
for j in range(1,i+1,1):
print(chr(64+i) ,end=" ")
print(" ")

Enter N:26
A
B B
C C C
D D D D
E E E E E
F F F F F F
G G G G G G G
H H H H H H H H
I I I I I I I I I
J J J J J J J J J J
K K K K K K K K K K K
L L L L L L L L L L L L
M M M M M M M M M M M M M
N N N N N N N N N N N N N N
O O O O O O O O O O O O O O O
P P P P P P P P P P P P P P P P
Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q
R R R R R R R R R R R R R R R R R R
S S S S S S S S S S S S S S S S S S S
T T T T T T T T T T T T T T T T T T T T
U U U U U U U U U U U U U U U U U U U U U
V V V V V V V V V V V V V V V V V V V V V V
W W W W W W W W W W W W W W W W W W W W W W W
X X X X X X X X X X X X X X X X X X X X X X X X
Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y
Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z

n=int(input("Enter N:"))
for i in range (1,n+1,1):
for j in range(1,i+1,1):
print(chr(64+j) ,end=" ")
print(" ")

Enter N:26
A
A B
A B C
A B C D
A B C D E
A B C D E F
A B C D E F G
A B C D E F G H
A B C D E F G H I
A B C D E F G H I J
A B C D E F G H I J K
A B C D E F G H I J K L
A B C D E F G H I J K L M
A B C D E F G H I J K L M N
A B C D E F G H I J K L M N O
A B C D E F G H I J K L M N O P
A B C D E F G H I J K L M N O P Q
A B C D E F G H I J K L M N O P Q R
A B C D E F G H I J K L M N O P Q R S
A B C D E F G H I J K L M N O P Q R S T
A B C D E F G H I J K L M N O P Q R S T U
A B C D E F G H I J K L M N O P Q R S T U V
A B C D E F G H I J K L M N O P Q R S T U V W
A B C D E F G H I J K L M N O P Q R S T U V W X
A B C D E F G H I J K L M N O P Q R S T U V W X Y
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

n=int(input("Enter N:"))
for i in range (n, 0, -1):
for j in range(1,i+1,1):
print(chr(64+i) ,end=" ")
print(" ")

Enter N:4
D D D D
C C C
B B
A

n=int(input("Enter N:"))
for i in range (1, n+1, 1):
for j in range(n, i-1, -1):
print(chr(64+j) ,end=" ")
print(" ")

Enter N:4
D C B A
D C B
D C
D

n=int(input("Enter N:"))
for i in range (1, n+1, 1):
for j in range(n, i-1, -1):
print(chr(65-i+j) ,end=" ")
print(" ")

Enter N:4
D C B A
C B A
B A
A

n=int(input("Enter N:"))
for x in range( 1, n+1, 1):
for k in range (1, n-x+1, 1):
print(" " , end= " " )
for j in range (1, x+1, 1):
print("* ", end= " ")
print(" ")

Enter N:5
*
* *
* * *
* * * *
* * * * *

n=int(input("Enter N:"))
for x in range( 1, n+1, 1):
for k in range (1, n-x+1, 1):
print(" " , end= " " )
for j in range (1, x+1, 1):
print("*", end= " ")
print(" ")

Enter N:5
*
* *
* * *
* * * *
* * * * *

x="ABCD"
for y in x:
print(ord(y))

#atring me kabhi range nhi aaega

65
66
67
68

x="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
for y in x:
print(ord(y))

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

string programs

wap to print alll characters of a string individally


x=input("Enter Message: ")
for y in x:
print(y)

Enter Message: ABCDEFGHIJKLMNOPQRSTUVWXYZ


A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
WAP TO COUNT VOWELS AAND
CONSONANTS FROMA A GIVEN STRING
x=input("Enter Message: ")
v=0
c=0
for i in x:
if i=='a'or i=='e'or i=='i'or i=='o'or i=='u' or i=='A' or i=='E'
or i=='O' or i=='I' or i=='U' :
v=v+1
else:
c=c+1
print("Vowel Is: ",v, "Consonants Are: ",c )

Enter Message: THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG
Vowel Is: 11 Consonants Are: 32

x=input("Enter Message: ")


print(len(x))

Enter Message: THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG
43

x=input("Enter Message: ")


v=0
c=0
for i in x:
if i=='a'or i=='e'or i=='i'or i=='o'or i=='u' or i=='A' or i=='E'
or i=='O' or i=='I' or i=='U' :
v=v+1
else:
c=c+1
print("Vowel Is: ",v, "Consonants Are: ",c )

WAP TO COUNT NO OF ALPHABETS


DIGITSAND SYMBOLS OF A GIVEN STRING
x=input("Enter Message: ")
alpha=0
dig=0
symbol=0
for i in x:
if i.isalpha() :
alpha=alpha+1
elif i.isdigit() :
dig=dig+1
else:
symbol=symbol+1
print("ALPHABETS ARE: ", alpha, "DIGITS ARE: ", dig, "SYMBOLS ARE: ",
symbol)

Enter Message: ABCD1234!@#$


ALPHABETS ARE: 4 DIGITS ARE: 4 SYMBOLS ARE: 4

WAP TO SEARCH A GIVEN CHARACTER IN A


STRNG IS PRESENT OR NOT
x=input("Enter Message: ")
y=input("Enter Character: ")
f=0
for i in x:
if i==y:
f=1
break
else:
f=0
if f==1:
print("PRESENT")
else:
print("ABSENT")

#concept of flag avriable and break

Enter Message: ABCXYZ


Enter Character: Y
PRESENT

WAP TO COUNT FFREQUENCY OF A


CHARCTER IN A GIVEN STRING
x=input("Enter Message: ")
y=input("Enter Character: ")
c=0
for i in x:
if i==y:
c=c+1
print("CHARACTER",y,"IS PRESENT",c, "TIMES")
Enter Message: ABABABAB
Enter Character: A
CHARACTER A IS PRESENT 4 TIMES

SLICE FN
''''list is a collection of multiple data items of diffrent data
types,
all the elements of list contains unique index which starts ftom xeero
and runs tilll (n-1)'''

#slice fn can seprate out particular range of index from list

x=[1,2,3,4,5,6,7]
print(x[0:8:1])

[1, 2, 3, 4, 5, 6, 7]

x=[1,2,3,4,5,6,7]
print(x)

[1, 2, 3, 4, 5, 6, 7]

x=[1,2,3,4,5,6,7]
print(x[:8])

[1, 2, 3, 4, 5, 6, 7]

x=[1,2,3,4,5,6,7]
print(x[-1:-8:-1])

[7, 6, 5, 4, 3, 2, 1]

x=[1,2,3,4,5,6,7]
print(x[-8:0])

[]

x=[1,2,3,4,5,6,7]
print(x[-8::1])

[1, 2, 3, 4, 5, 6, 7]

x=[1,4,6,7,9,10,12]
print(x[-4::1])

[7, 9, 10, 12]

x=[1,4,6,7,9,10,12]
print(x[-1::1])
[12]

x=[1,4,6,7,9,10,12]
print(x[::-1])

[12, 10, 9, 7, 6, 4, 1]

x=[1,2,3,4,5,6,7,8]
print(x[0:4])

[1, 2, 3, 4]

x=[1,2,3,4,5,6,7]
print(x[3:8])

[4, 5, 6, 7]

x=[1,2,3,4,5,6,7]
print(x[-4::])

[4, 5, 6, 7]

x=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18]
print(x[::-1])

[18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]

x=[1,2,3,4,5,6,7]
print(x[0:8:2])

[1, 3, 5, 7]

x=[1,2,3,4,5,6,7,8,9,10]
print(x[1:11:2])

[2, 4, 6, 8, 10]

x="hello"
print(x[0:5:1])

hello

x="hello"
print(x[::-1])

olleh

wap to check given string is palindrome or not


x=input("String: ")
y=x[::-1]
if x==y:
print("PALINDROME")
else:
print("NOT PALINDROME")

String: NANAN
PALINDROME

user defined fn (udf) 1outta4


def add(a,b):
c=a+b
print(c)
x=int(input("Enter 1st NO: "))
y=int(input("Enter 2nd NO: "))
add(x,y)

Enter 1st NO: 5


Enter 2nd NO: 5
10

def factorial(x):
f=1
i=1
while i<=x:
f=f*i
i=i+1
print("Factorial Is: ", f)
y=int(input("Enter No: "))
factorial(y)

Enter No: 5
Factorial Is: 120

recursive fn
#when a fn calls itself repetively inside its own defination it is
called recursion( recursive fn)

def factorial(x):
if x==1 or x==0:
return 1
else:
return x*factorial(x-1)
y=int(input("Enter No: "))
z=factorial(y)
print("Ans Is: ", z)
Enter No: 5
Ans Is: 120

You might also like