Tuesday 30 December 2014

Multiples of 3 or 5


Question: Find all the numbers which are multiples of 3 or 5 below 1000. For example if you consider numbers below 10 then then the answer should be [3,5,6,9] if you consider numbers below 20 then the answer should be [3,5,6,9,10,12,15,18]. Similarly find the numbers which are divisible by 3 or 5 below 1000.

Answer: I have answered this question with required number of comments. Please do ask me if you have doubt.

#Defining using a function
def multiples(n):#Argument should be the required number of numbers
 numbers = [] #defining a list to append the numbers in the list.
 for i in range(1,n):#looping through through the numbers
  if i%3==0 or i%5==0:#Condition to check whether the number is divisible by 3 or 5
   numbers.append(i)#appending the number into the list
 print numbers#Finally print the numbers

#using the function for the numbers below 1000
multiples(1000)
Output:
[3, 5, 6, 9, 10, 12, 15, 18, 20, 21, 24, 25, 27, 30, 33, 35, 36, 39, 40, 42, 45, 48, 50, 51, 54, 55, 57, 60, 63, 65, 66, 69, 70, 72, 75, 78, 80, 81, 84, 85, 87, 90, 93, 95, 96, 99, 100, 102, 105, 108, 110, 111, 114, 115, 117, 120, 123, 125, 126, 129, 130, 132, 135, 138, 140, 141, 144, 145, 147, 150, 153, 155, 156, 159, 160, 162, 165, 168, 170, 171, 174, 175, 177, 180, 183, 185, 186, 189, 190, 192, 195, 198, 200, 201, 204, 205, 207, 210, 213, 215, 216, 219, 220, 222, 225, 228, 230, 231, 234, 235, 237, 240, 243, 245, 246, 249, 250, 252, 255, 258, 260, 261, 264, 265, 267, 270, 273, 275, 276, 279, 280, 282, 285, 288, 290, 291, 294, 295, 297, 300, 303, 305, 306, 309, 310, 312, 315, 318, 320, 321, 324, 325, 327, 330, 333, 335, 336, 339, 340, 342, 345, 348, 350, 351, 354, 355, 357, 360, 363, 365, 366, 369, 370, 372, 375, 378, 380, 381, 384, 385, 387, 390, 393, 395, 396, 399, 400, 402, 405, 408, 410, 411, 414, 415, 417, 420, 423, 425, 426, 429, 430, 432, 435, 438, 440, 441, 444, 445, 447, 450, 453, 455, 456, 459, 460, 462, 465, 468, 470, 471, 474, 475, 477, 480, 483, 485, 486, 489, 490, 492, 495, 498, 500, 501, 504, 505, 507, 510, 513, 515, 516, 519, 520, 522, 525, 528, 530, 531, 534, 535, 537, 540, 543, 545, 546, 549, 550, 552, 555, 558, 560, 561, 564, 565, 567, 570, 573, 575, 576, 579, 580, 582, 585, 588, 590, 591, 594, 595, 597, 600, 603, 605, 606, 609, 610, 612, 615, 618, 620, 621, 624, 625, 627, 630, 633, 635, 636, 639, 640, 642, 645, 648, 650, 651, 654, 655, 657, 660, 663, 665, 666, 669, 670, 672, 675, 678, 680, 681, 684, 685, 687, 690, 693, 695, 696, 699, 700, 702, 705, 708, 710, 711, 714, 715, 717, 720, 723, 725, 726, 729, 730, 732, 735, 738, 740, 741, 744, 745, 747, 750, 753, 755, 756, 759, 760, 762, 765, 768, 770, 771, 774, 775, 777, 780, 783, 785, 786, 789, 790, 792, 795, 798, 800, 801, 804, 805, 807, 810, 813, 815, 816, 819, 820, 822, 825, 828, 830, 831, 834, 835, 837, 840, 843, 845, 846, 849, 850, 852, 855, 858, 860, 861, 864, 865, 867, 870, 873, 875, 876, 879, 880, 882, 885, 888, 890, 891, 894, 895, 897, 900, 903, 905, 906, 909, 910, 912, 915, 918, 920, 921, 924, 925, 927, 930, 933, 935, 936, 939, 940, 942, 945, 948, 950, 951, 954, 955, 957, 960, 963, 965, 966, 969, 970, 972, 975, 978, 980, 981, 984, 985, 987, 990, 993, 995, 996, 999]
  Without using lists:

#Defining using a function
def multiples(n):#Argument should be the required number of numbers
 for i in range(1,n):#looping through through the numbers
  if i%3==0 or i%5==0:#Condition to check whether the number is divisible by 3 or 5
   print i #Printing the numbers which satisfy the condition

#using the function for the numbers below 1000
multiples(1000)

Without using function:

for i in range(1,1000):#looping through through the numbers below 1000
 if i%3==0 or i%5==0:#Condition to check whether the number is divisible by 3 or 5
  print i #Printing the numbers which satisfy the condition
Output:  Both of the last two programs have the same output and is as follows:

3
5
6
9
10
12
15
18
20
21
24
25
27
30
33
35
36
39
40
42
45
48
50
51
54
55
57
60
63
65
66
69
70
72
75
78
80
81
84
85
87
90
93
95
96
99
100
102
105
108
110
111
114
115
117
120
123
125
126
129
130
132
135
138
140
141
144
145
147
150
153
155
156
159
160
162
165
168
170
171
174
175
177
180
183
185
186
189
190
192
195
198
200
201
204
205
207
210
213
215
216
219
220
222
225
228
230
231
234
235
237
240
243
245
246
249
250
252
255
258
260
261
264
265
267
270
273
275
276
279
280
282
285
288
290
291
294
295
297
300
303
305
306
309
310
312
315
318
320
321
324
325
327
330
333
335
336
339
340
342
345
348
350
351
354
355
357
360
363
365
366
369
370
372
375
378
380
381
384
385
387
390
393
395
396
399
400
402
405
408
410
411
414
415
417
420
423
425
426
429
430
432
435
438
440
441
444
445
447
450
453
455
456
459
460
462
465
468
470
471
474
475
477
480
483
485
486
489
490
492
495
498
500
501
504
505
507
510
513
515
516
519
520
522
525
528
530
531
534
535
537
540
543
545
546
549
550
552
555
558
560
561
564
565
567
570
573
575
576
579
580
582
585
588
590
591
594
595
597
600
603
605
606
609
610
612
615
618
620
621
624
625
627
630
633
635
636
639
640
642
645
648
650
651
654
655
657
660
663
665
666
669
670
672
675
678
680
681
684
685
687
690
693
695
696
699
700
702
705
708
710
711
714
715
717
720
723
725
726
729
730
732
735
738
740
741
744
745
747
750
753
755
756
759
760
762
765
768
770
771
774
775
777
780
783
785
786
789
790
792
795
798
800
801
804
805
807
810
813
815
816
819
820
822
825
828
830
831
834
835
837
840
843
845
846
849
850
852
855
858
860
861
864
865
867
870
873
875
876
879
880
882
885
888
890
891
894
895
897
900
903
905
906
909
910
912
915
918
920
921
924
925
927
930
933
935
936
939
940
942
945
948
950
951
954
955
957
960
963
965
966
969
970
972
975
978
980
981
984
985
987
990
993
995
996
999

Monday 29 December 2014

Multiples of 3 and 5 and their sum


Question: Find the multiples of 3 and 5 and add them till the numbers below 1000. For example if you consider numbers below 10 you will have [3.5,6,9] as the numbers which are divisible by 3 and 5. Their sum will be 23(3+5+6+9), where 23 is the required answer for numbers below 10(<10). Similarly if we consider numbers below 20 you will have [3,6,5,9,10,12,15,18] as the numbers which are divisible by either 3 or 5. Their sum will be 78(3+6+5+9+10+12+15+18) which will be the required answer for numbers below 20.
Similarly find out the sum for the numbers below 1000?

Answer: I have solved this question in two ways, first one I have answered this question using functions and in the second method which doesn't use functions. I have commented the code so that everyone will understand it perfectly. Please do tell me if you don't understand. I will for sure make it clear for you.

Approach using Functions:

#Defining a function as the code may be used any number of times.
#Step1:Defining the name of function
def sum_multiple(n):
#Initialize a variable sum1 = 0
    sum1 = 0
#Use the for loop to loop n-1 times
    for number in range(1,n):
#Make decision if the number is divisible by 3 or 5. Using 'OR' operator
        if number % 3 == 0 or number % 5 == 0:
#If condition is true add the value
            sum1 += number
#Finally print the sum.
    print sum1

#Use the function call for first 9 numbers.
sum_multiple(10) #Expected value of 23

#Use it to give the value for first 999 numbers(numbers below 1000).
sum_multiple(1000) #Value is 233168
Output:

23
233168

Normal Approach:

#Initialize a variable sum1 = 0
sum1 = 0
#Use the for loop to loop 999 times
for number in range(1,1000):
#Make decision if the number is divisible by 3 or 5. Using 'OR' operator
    if number % 3 == 0 or number % 5 == 0:
#If condition is true add the value
        sum1 += number
#Finally print the sum.
print sum1
Output:
233168

Note:This problem was found on Project Euler

Installing python IDLE on your personal computer


Coming soon :)

Sunday 28 December 2014

What is python, overview


    Python is an easy to learn high level programming language. It is also an object oriented programming. It has most of the capabilities that other programming language has. You can make games, graphics, build websites, blogs and many others. Even for your information Google the worlds most famous search engine used python to build search engine page.

    Now you may have a doubt why I should only use python, is it for the reason it is easy? I don't say that you should learn python for the reason that it is easy. I suggest you to choose a smarter choice. If you compare Java, C, C++ and many other high level programming languages like python, python is easy to use, easy to read, easy to build. Even python was created by Guido Van Rossum(Who may be a lover of C(may be because, the official documentation always cites to C)) developed python for the reason that a program should be easy to read, free for all, easy to build.

    Not only for the reasons stated above, python has a large community of developers around the world. There are many people contributing for this python software foundation day and night. The contribution may be in the form of donation or may be developing a module or package or even may be a software and contributing to this open source.

    While python is inbuilt in Linux and Unix computers and also on Mac systems. But on windows you should install it by downloading the installer file on your computer. You can find this tutorial, installing python on your computer. Okay while all the above statements are like brain wash for you I will give you some applications or success stories of python. While the full list can be seen here: Success Stories.

    I have only stated a few success stories in python but there are a lot more to know. But all these can only be done if you have a basic understanding of what python is and how to program in python at an advanced level. But if you want to know python at advanced level then you should know python at basic level. So what are you waiting for, get started. Start learning python. Start your python by installing it on your Personal Computer. 

    Saturday 27 December 2014

    Contributions and Preface

    **Table of contents**
    Contributions and Preface
    Own docs python tutorial is an initiative to provide python tutorial to everyone. Actually this will be my notes of all the references I have made to learn python. Presently contributions for this tutorial is only me. But I think my community will become wide and I will have a wide range of people learning this tutorial and help me correct any mistakes I have made. May be this will serve as reference to many people in the world. I am posing these tutorials for free so that every person who have access to internet can learn python.

    To mention present contributors are:
    1. Anivarth
    2.Blogger(A platform)
    3. hilite.me
    4. Sora Templates

    I think in a few days more than material names I will include person names in the above. I would also request everyone to go through the tutorial and help me also in grammatical mistakes if I make any. 

    I have tried to make this tutorial as limited as possible so that as a beginner no one should feel un comfortable. For experience in programming I have included examples in every tutorial. I would like to highlight that this tutorial is for everyone. Everyone includes people who already have programming experience, or who never had programming experience. If you knew some basics of programming in any programming language that would be an added advantage. However don't worry even if you know any programming language or not. Just keep your experience if any aside and think yourself as if you are a beginner. Because if have to learn anything you should be broad minded. Broad minded in the sense you should be ready to read anything and everything. 

    Finally about copyright, all the contents of this tutorial have been copyrighted. After completing the tutorials I will write I will even copyright the whole set of tutorials as a book. This will not have any copyright problems for me afterwards. I request everyone not to copy any parts of this book for commercial use. But you can share, store or even print for your own reference. If you want to sell these tutorials there should be a written permission. All the works of this website are licensed under Creative Commons 4.0 license and copyrighted at copyrighted.com You can find the link to copyright at the end of this page. Finally Thank you for reading this tutorial and helping me to improve this tutorials. 

    Contributed to Open Source Community

    Thank you. Get started now by clicking the link below 

    >>1.What is python,overview
    Copyright: Copyrighted.com Registered & Protected 
GEIS-UGLS-0XSG-ILKD

    Owndocs Logo

    Owndocs official logo

    This is the logo of owndocs. This was created on December 27 2014. This was created using Montez Regular font on photoshop. I think this logo is good and have started using this. If you have any suggestion please do comment or contact me. This logo is copyrighted. The copyright also includes several color combinations not mentioned here.

    There is also another version of owndocs logo which you can see below.The copyright includes different color combinations for this logo also.
    Own docs black and white

    Logo placed on every page of the website is:

    Owndocs

    You can use it for giving a link to my website and also can be used where there is a link to owndocs.blogspot.com website. You can also share it on social media again with a link established. You can also contact me for the rights if you want to use it for further usage. 

    Copyright for these logos is registered and can be viewed here:

    Owndocs official logo: Copyright link
    Owndocs black and white:Copyright link
    Owndocs: Copyright link               

    Please contact me if you have any queries.

    Thank you.