Coders PlayGround

Learn to code and change the future!

Tuesday, 29 August 2017

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

Print Function

August 29, 2017

Hello friends! This is a simple program to print on Screen


To print the content we simply use the print() function.
Whatever is written inside the double or single quotes gets printed.

Check out the following example:



print ("Welcome to TechandCoders site")

# we can also use single quotes

print ('Let us learn python programming')

# '\' escape character

print ("She's here!")
print('She\'s here!!!')






Now, suppose you want to print the value of a variable. How would you do it?

x = 5

# Simply write the name of the variable without any single or double quotes.

print (x)

Run this code and check


Please comment and share!
Any queries, mail me at: techandcoders@gmail.com

Thank you!

Read More
PropellerAds