diff --git a/Books/Automate the Boring Stuff with Python (2015).pdf b/Books/Automate the Boring Stuff with Python (2015).pdf new file mode 100644 index 0000000..796bf9c Binary files /dev/null and b/Books/Automate the Boring Stuff with Python (2015).pdf differ diff --git a/Books/Python - Learning 4th Edition.pdf b/Books/Python - Learning 4th Edition.pdf new file mode 100644 index 0000000..a9e6998 Binary files /dev/null and b/Books/Python - Learning 4th Edition.pdf differ diff --git a/README.md b/README.md index 253ff5f..5fdf3d2 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ If you are new to git and github, to make your first contributions, visit this: ## Diving Into Python ### Book +- [Python For You and me by Kushal Das](https://pymbook.readthedocs.io/en/latest/) - [Learn Python the Hard Way by Zed Shaw](Books/LPTHW.pdf) ### Online Courses @@ -16,4 +17,8 @@ If you are new to git and github, to make your first contributions, visit this: - [Python Docs](https://docs.python.org/3/tutorial/) - [TutorialsPoint](https://www.tutorialspoint.com/python/index.htm) +### Youtube Channels +- [thenewboston](https://www.youtube.com/watch?v=HBxCHonP6Ro&list=PL6gx4Cwl9DGAcbMi1sH6oAMk4JHw91mC_) +- [Python Docs](https://www.youtube.com/watch?v=oVp1vrfL_w4&list=PLQVvvaa0QuDe8XSftW-RAxdo6OmaeL85M) + For some Sample Problems and to get started [click here](Src) diff --git a/Src/Largefactorial.py b/Src/Largefactorial.py new file mode 100644 index 0000000..3b8276a --- /dev/null +++ b/Src/Largefactorial.py @@ -0,0 +1,15 @@ +#Input the number whose factorial is to be calculated +def range_prod(lo,hi): + if lo+1 < hi: + mid = (hi+lo)//2 + return range_prod(lo,mid) * range_prod(mid+1,hi) + if lo == hi: + return lo + return lo*hi +# The above function will reduce the multiplicaion of higher no. and could give 10X better performance than the previous one. +def fact(n): + if n < 2: + return 1 + return range_prod(1,n) +n = int(input("Enter number whose factorial is wanted ")) +print " %d! = %d " %(n,fact(n)) diff --git a/Src/Palindrome.py b/Src/Palindrome.py new file mode 100644 index 0000000..9b60c62 --- /dev/null +++ b/Src/Palindrome.py @@ -0,0 +1,27 @@ +# An example for checking whether the string is palindrome or not +# 1st of all what the palidrome string is. +# A palindrome is a word, number, or other sequence of characters which reads the same backward as forward, such as madam or racecar. +# Some well-known English palindromes are, "Able was I ere I saw Elba",[2] "A man, a plan, a canal – Panama",[3] "Madam, I'm Adam" and "Never odd or even". + +# so here is a code + +# by using for loop +x=str(input()) +y=x +a=len(x) +for i in range(0,a): + if(x[i]!=y[a-i-1]): + print("Not Palindrome") + break +if(i==a-1): + print("Palindrome") + + +# it is by list method + +x=(input()) +x=list(x) # this converts x str into list +if(x==x[::-1]): # x[::-1] implies it reverse the x list + print("Palindrome") +else: + print("Not Palindrome") diff --git a/Src/PrimeNumbers/PrimeRange_EffectiveApproach.py b/Src/PrimeNumbers/PrimeRange_EffectiveApproach.py new file mode 100644 index 0000000..16b9b4d --- /dev/null +++ b/Src/PrimeNumbers/PrimeRange_EffectiveApproach.py @@ -0,0 +1,16 @@ +# Python program to display all the prime numbers within an interval +import math +lower = int(input("Enter lower range: ")) +upper = int(input("Enter upper range: ")) +print("Prime numbers between",lower,"and",upper,"are:") +for num in range(lower,upper + 1): + # prime numbers are greater than 1 + if num > 1: + test=int(math.sqrt(num)) +#here we will iterate upto sqrt of a number not to the number itself, the reason is : any composite number N must have atleast one factor in the range 2 to sqrt(N), which is enough to find out whether N is prime or not. + #iterating upto sqrt(num) + for i in range(2,test+1): + if (num % i) == 0: + break + else: + print(num) \ No newline at end of file diff --git a/Src/PrimeNumbers/PrimeRange_NaiveApproach.py b/Src/PrimeNumbers/PrimeRange_NaiveApproach.py new file mode 100644 index 0000000..a145c15 --- /dev/null +++ b/Src/PrimeNumbers/PrimeRange_NaiveApproach.py @@ -0,0 +1,15 @@ +# Python program to display all the prime numbers within an interval +lower = int(input("Enter lower range: ")) +upper = int(input("Enter upper range: ")) + +print("Prime numbers between",lower,"and",upper,"are:") + +for num in range(lower,upper + 1): + # prime numbers are greater than 1 + if num > 1: + for i in range(2,num): + #iterating upto num + if (num % i) == 0: + break + else: + print(num) diff --git a/Src/decimaltobinary.py b/Src/decimaltobinary.py new file mode 100644 index 0000000..fb3b78e --- /dev/null +++ b/Src/decimaltobinary.py @@ -0,0 +1,12 @@ +def dec2bin(n): + b = '' + while n != 0: + b = b + str(n % 2) + n = int(n / 2) + return b[::-1] + +def d2b(n): + if n == 0: + return '' + else: + return d2b(n//2) + str(n%2) \ No newline at end of file diff --git a/Src/factorial/Largefactorial.py b/Src/factorial/Largefactorial.py new file mode 100644 index 0000000..7999617 --- /dev/null +++ b/Src/factorial/Largefactorial.py @@ -0,0 +1,17 @@ +#Input the number whose factorial is to be calculated +def range_prod(lo,hi): + if lo+1 < hi: + mid = (hi+lo)//2 + return range_prod(lo,mid) * range_prod(mid+1,hi) + if lo == hi: + return lo + return lo*hi +# The above function will reduce the multiplicaion of higher no. and +#could give 10X better performance than the conventional one. +def fact(n): + if n < 2: + return 1 + return range_prod(1,n) +n = int(input("Enter number whose factorial is wanted ")) +print " %d! = %d " %(n,fact(n)) +#this code could calculate factorial of large numbers like 10^5. diff --git a/Src/factorial/factorial.py b/Src/factorial/factorial.py new file mode 100644 index 0000000..3643107 --- /dev/null +++ b/Src/factorial/factorial.py @@ -0,0 +1,12 @@ +#Input the number whose factorial is to be calculated +def fact(n): + if(n>0): + return (n*fact(n-1)) + else: + return (1) + +n = int(input("Enter number whose factorial is wanted ")) +print " %d! = %d " %(n,fact(n)) +#this code works appropriately only for smaller values of N, more specifically +#it works only upto 973, afterforth maximum recursion depth for function fact +#exceedes and it ends up being collapsed. diff --git a/Src/octaltobinary.py b/Src/octaltobinary.py new file mode 100644 index 0000000..25a6560 --- /dev/null +++ b/Src/octaltobinary.py @@ -0,0 +1,8 @@ +print("Enter 'x' for exit."); +octal = input("Enter any number in Octal Format: "); +if octal == 'x': + exit(); +else: + dec = str(int(octal, 8)); + decm = int(dec); + print(octal,"in Binary =",bin(decm)); \ No newline at end of file diff --git a/Src/trianglearea.py b/Src/trianglearea.py new file mode 100644 index 0000000..07e2f35 --- /dev/null +++ b/Src/trianglearea.py @@ -0,0 +1,4 @@ +import math +b=input("Enter the number of base of triangle: ") +h=input("Enter with the height of triangle: ") +print "Triangle area:",(b*h)/2 \ No newline at end of file diff --git a/Thoughts/Pip.md b/Thoughts/Pip.md new file mode 100644 index 0000000..141dce1 --- /dev/null +++ b/Thoughts/Pip.md @@ -0,0 +1,11 @@ +**Pip** + +Pip is a rather simple concept of Python, but it's one that makes Python so amazing. +Pip is the Python package manager, and it helps you install everything you need to make +your program run. Unlike other languages, pip makes dependencies extremely easy. + +You can use pip in the cmd by simply running the command 'pip' +Look through all of the options you might want to use, but many people just use +'pip install ', and it works like magic! tada! + +Example: pip install tensorflow