Coders PlayGround

Learn to code and change the future!

Tuesday, 29 August 2017

For Loop in Python3

August 29, 2017

Hello friends, lets learn about for loop in python.
The for loop in python is bit different than C. 

Rather than always iterating over an arithmetic progression of numbers (like in Pascal), or giving the user the ability to define both the iteration step and halting condition (as C), Python’s for statement iterates over the items of any sequence (a list or a string), in the order that they appear in the sequence.


Check out this program:

list1 = [1,5,4,6,9,8,7,1,5,2,0,1,3]

for eachno in list1:
  print (eachno)

# highlight and tab to indent
# indentation is important in Python


print ("Using range function...")
# xrange in Python 2.7
# range built in function

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


# prints from 1 --> 10

 
Output
Read More

While Loop in Python3

August 29, 2017
Hello friends, lets learn about flow control Statements

In this post, I'll explain about while loop 

The syntax of while loop:

counter_var 
while condition:
    # Code to execute
    Increment/Decrement the counter_var


Remember, in Python indentation plays a very important role.
We do not use curly brackets for defining the while loop instead indentation is used to define the code within the while loop.



Check out the following code:


condition = 1

while condition < 10:
  print(condition)
  condition += 1

# Infinte loop
# Ctrl C to break the loop
while True:
  print ("Processing...")


Output
Read More

Math Functions

August 29, 2017

Hello friends, lets learn about the math functions of Python3



import math

a = 2
b = 5

print(a+b)
print(a-b)
print(a/b)
print(a*b)
print(a**b)
print("Value of pi: ", math.pi)
print("Ceil function",math.ceil(5.4))
print("Floor function",math.floor(5.4))
print("Absolute function",math.fabs(-5))
print("Factorial function",math.factorial(5))
print("Greates common divisor function",math.gcd(21,45))
print("Radian to degree function",math.degrees(30))
print("Degree to radian function",math.radians(30))

print("Complex no: ", "\n", "(3+5j) + (5 + 2j) = ",(3+5j) + (5 + 2j))


Output


Python supports other types of numbers, such as Decimal and Fraction. Python also has built-in support for complex numbers, and uses the j or J suffix to indicate the imaginary part (e.g. 3+5j).

There are many other functions such as log, trigonometric functions 

Read More

Introduction Of Python

August 29, 2017

Hello friends, lets learn python programming!!!
Have you ever wondered why Python is named as Python???

Lets see the features and other advantages of Python.



Python is easy to learn and is a high level language. Python offers much more structure and support for large programs than shell scrips or batch files.

Python allows you to split your program into modules that can be reused in other Python programs. It comes with a large collection of standard modules that you can use as the basis of your programs — or as examples to start learning to program in Python. Some of these modules provide things like file I/O, system calls, sockets, and even interfaces to graphical user interface toolkits like Tk.

Python is an interpreted language, which can save you considerable time during program development because no compilation and linking is necessary. The interpreter can be used interactively, which makes it easy to experiment with features of the language, to write throw-away programs, or to test functions during bottom-up program development. It is also a handy desk calculator.

Python enables programs to be written compactly and readably. Programs written in Python are typically much shorter than equivalent C, C++, or Java programs, for several reasons:
  • the high-level data types allow you to express complex operations in a single statement;
  • statement grouping is done by indentation instead of beginning and ending brackets;
  • no variable or argument declarations are necessary.
Python is extensible: if you know how to program in C it is easy to add a new built-in function or module to the interpreter, either to perform critical operations at maximum speed, or to link Python programs to libraries that may only be available in binary form (such as a vendor-specific graphics library). Once you are really hooked, you can link the Python interpreter into an application written in C and use it as an extension or command language for that application.

By the way, the language is named after the BBC show “Monty Python’s Flying Circus” and has nothing to do with reptiles. Making references to Monty Python skits in documentation is not only allowed, it is encouraged!


References: https://docs.python.org/3/tutorial/appetite.html
Read More
PropellerAds