Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Awesome-Scripts/fibonacci.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ def fib(n):


n = int(input("Enter a number: "))
print(fib(n))
print("Fibonacci series:")
for i in range(n):
print fib(n)
41 changes: 41 additions & 0 deletions Awesome-Scripts/spiralmatrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
n=int(input("Enter the size of matrix:"))
t=1
r=0 # r stands for row
c=0 # c stands for column
matrix=[[0 for x in range(n)]for y in range(n)] # to initialise the matrix
if n%2==0:
k=n/2
else:
k=(n/2)+1
for i in range(k):
while c<n:
matrix[r][c]=t
t=t+1
c=c+1
r=r+1
c=c-1
while r<n:
matrix[r][c]=t
t=t+1
r=r+1
r=r-1
c=c-1
while c>=i:
matrix[r][c]=t
c=c-1
t=t+1
c=c+1
r=r-1
while r>i:
matrix[r][c]=t
t=t+1
r=r-1
r=r+1
n=n-1
c=c+1
for m in matrix:
print m
ln = ""
for i in m:
ln += str(i) + " "
print(ln)
45 changes: 24 additions & 21 deletions Python-Syntax.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
# Basic Python Syntax
## Python 2

1. Printing output in python 2 :-
print "argument that you want to print"
- Printing output in **Python 2** :-
`print "argument that you want to print"`
OR
`print 'argument that you want to print'`

2. mathematical operators :-
x = 8
y = 4
print x+y # it wil give outout of sum of x and y
print x-y # it will give difference of x and y
print x/y # it will give quotient when x is divided by y
print x%y # it is modulo function and gives remainder when x is divied by y
print x ** y # it means x^y. it is way to represnt power operator
- Mathematical operators :-
>`x = 8`
>`y = 4`
>`print x + y` # it will give output of sum of x and y
>`print x - y` # it will give difference of x and y
>`print x / y` # it will give quotient when x is divided by y
>`print x % y` # it is modulo function and gives remainder when x is divied by y
>`print x ** y` # it means x^y. it is way to represent power operator

3. single line comments can be given by putting # before a line
- Single line comments can be given by putting **#** before a line

4. multi line comments can be given by putting 3 double quotes befire and after the lines.
- Multi line comments can be given by putting 3 double quotes before and after the lines.

example of putting multiline comments is :
""" hello
how are you """
example of putting multiline comments is :
**""" hello
how are you """**

5. To validate a variable to be an integer or a string, use 'isinstance(<var>, <type>)'
it accepts two parameter
1. variable name
2. Type to be validated
example: isinstance(a, dict) , isinstance(num, integer)
It return True if true else false.
- To validate a variable to be an integer or a string, use `isinstance(<var>, <type>)`
it accepts two parameter:
- variable name
- Type to be validated

example: isinstance(a, dict) , isinstance(num, integer)
It returns True if true else False.