Posts

Cracking the Code: Make Cash from Code

Image
Inspired from  https://medium.com/@sanatjha4/cracking-the-code-7-creative-ways-to-start-earning-money-from-programming-e4343c6f2534 Attention all programmers! Are you looking for ways to turn your coding skills into a lucrative income stream? Look no further! There are many opportunities available for programmers to make money in today's digital age. Here are some tips to get started: Freelance: Offer your services as a freelancer and work on projects that interest you. You can find freelance jobs on various platforms such as Upwork, Freelancer, and Fiverr. Create Your Own Software: Develop software that solves a problem or meets a need that is not currently being met. You can sell your software on various platforms such as the App Store or Google Play. Teach Programming: Create online courses or tutorials and sell them on platforms such as Udemy or Teachable. You can also offer one-on-one coaching or mentoring services to aspiring programmers. Participate in Coding Competitions: S

Comments

Comments In Python, comments are used to provide explanatory notes or documentation within the code.  Comments are lines of text that are ignored by the Python interpreter and are intended for human readers. Python has two types of comments: single-line comments and multi-line comments. Single-line comments start with the hash character (#) and continue until the end of the line.  Multi-line comments, also known as block comments, start and end with three quotes ("""). They can be used to provide detailed explanations of a block of code or to temporarily disable code during development. It can span multiple lines and is useful for providing detailed documentation or temporarily disabling code during development.  ---------------------------------------------- Code:- print("Let's learn comments")    #This is a comment and will be ignored by the system Output:- Let's learn comments ---------------------------------------------- It's worth noting that

Dictionaries

Dictionaries Dictionaries offer you a way to store data in a key pair way. You can get any assigned value through the key of it. Dictionaries are created using curly brackets{}. Values are assigned to keys using a colon: and different pairs are separated using a comma. They are used in the following way: - ------------------------------------------------------ Code: - myDict = { "name" : "python" , "level" : "easy" } print(myDict["name"]) Output: - python ------------------------------------------------------ One can also add new values using new key names that do not exist in the dictionary or change the value of existing. ------------------------------------------------------ Code: - myDict = { "name" : "python" , "level" : "easy" } myDict["level"] = "very easy" print(myDict["level"]) Output: - very easy ------------------------------------------------------

Tuples

Tuples Tuples are almost the same as lists but once the values are declared they can not be changed which means they are immutable. They are declared by brackets (). Trying to make changes in tuples gives you an error. -------------------------------- Code: - mytuple = ("python",9,"is",True,"awesome") print(mytuple[0],mytuple[1],mytuple[2]) Output: - python is awesome -----------------------------------

Lists

Lists In variables, one name can contain one value.  But when you need to store many values with one name, we use lists. To create a list we use square brackets[] with comma-separated values. A list can contain different types of values. ------------------------------------------------------------- Code: - myList = [5,8,"python",True,60] print(myList) Output: - [5,8,"python",True,60] -------------------------------------------------------------- To access a specific value from a list we use square brackets after the name of the list and put the index number in the bracket. ------------------------------------------------------------- Code: - myList = [5,8,"python",True,60] print(myList[2]) Output: - python -------------------------------------------------------------- ***Note that list indexing starts from 0 and not from 1*** The same way one can change the value of an index in a list. ------------------------------------------------------------- Code: - m

User-defined functions

User-defined functions Python allows you to create your own functions. To do so first we need to define the name of the function using the 'def' keyword. Then we have to make a block of code that will run when we call the function. Remember that just defining a function is not enough, we also have to call it in the code. --------------------------------------------------- Code:- def myfunc():          #making the function     x = "This is an output from my user-defined function."     print(x) myfunc()                   #calling the function Output:- This is an output from my user-defined function. ---------------------------------------------------- Here a question arises that what is the use of defining functions. It is useful when you have to use a long set of code many times in a whole program. You just need to define the function once and then use it as many times as you want. To make a function that takes some arguments and returns an output you need to declare v

Conditional statements

Conditional statements Conditional statements help us run a block of code only if a specific condition is satisfied. We use if keyword for the same. If comparison operator returns a True then the block of code will run or else it will be skipped. -------------------------------------------------- code:- if 5 < 7:      print('yes five is less than seven') output:- yes five is less than seven ---------------------------------------------------- Here 5 < 7 returned a true and so the code was executed. *** Note that before print statement there are indentations that tell python that it is a part of that block code.*** We use else keyword to declare a block of code that will be executed if the previous if condition is not satisfied. -------------------------------------------------- code:- age = int(input("enter your age: ")) if age >= 18:      print('yeah!!! You can drive.') else:      print("Sorry but you are too young to drive") output:- enter

Booleans

Booleans In programming, you often need to know if an expression is True or False. You can evaluate any expression in Python, and get one of two answers, True or False. When you compare two values, the expression is evaluated and Python returns the Boolean answer: ------------------------------------------------------- code:- print(5 > 3) print(10 < 5) print(100 == 99) output:- True False False --------------------------------------------------------- You can also store boolean values in variables. ------------------------------------------------------- code:- x = 10 > 3 print(x) output:- True --------------------------------------------------------- To get a boolean value comparison operators are used. There are different comparison operators in python. Operator                                            Name                                                          Example ==                                                          Equal                            

String Slicing

String Slicing We can access a part of a string by its position starting from 0. To do so we need to put the position number inside [sqaure brackets] after the string. ------------------------------------------- code:- mystr = "Hello World" print(mystr[3]) print(mystr[6]) output:- l W ------------------------------------------- ***Note that positions always start from 0 and not 1.*** In the above example, the positions of the string are:- H         - 0 e          - 1 l           - 2 l           - 3 o          - 4             - 5 W        - 6 o          - 7 r          - 8 l          - 9 d          - 10 To get a long part out of a string you can give two positions like [5:9] which will give you a string taken from the main string's 5 th to 9 th position. ------------------------------------------- code:- mystr = "Hello World" print(mystr[0:5]) output:- Hello -------------------------------------------

#9 - String Concatenation

Image
String Concatenation Now, we are going to do some addition operation with texts. Don't be confused. You will understand everything. What is String Concatenation? String Concatenation is simply joining two or more strings to form one string. To do so, we simply use the plus (+) symbol. Let's look at some of the example codes. Caution: This methods only work on strings and trying them on different data types may lead to an unknown output or become a reason for errors in your code. What is in our next step? After learning so many things we are now going to make our first program of a calculator. Calculator

#8 - Input function

Image
Input function Till now we have learned many things and now we are going towards taking inputs from the user. This is as easy as the print function.  So how to do it? All we have to do is to use Input() function . Wherever this function is in the code, the execution stops and waits for the user to enter some text in it as an input. If we want to pass any string as a hint for the user, we give it as an argument to the function which means we put it in the parenthesis. We also need to store the input data into a variable for further processing and so an input function always has a variable declaration in the starting. Always remember that the given input is by default in a string type and you need to convert it into any desired data type to perform anything on the data. Let's have a look at an example code:- First, we took the input from the user and saves it in a variable named name . Then we gave an output using that variable. By default, the input given is in string type but we ca

Calculator - Our first project

Image
Calculator Now, after learning so much, we are going to write our first real program that is a calculator. So, let's get started. What will be the final output? Som what our code will actually do is that first it will take two inputs that are the two numbers that the user wants to calculate and then the code will perform all the four main math operations i.e addition, subtraction, multiplication, and divide on it and then tell the result. Step 1: Taking input from the user. The first thing that we need to do is to take input from the user which is very easy to be done. We will be taking two inputs that will be the two numbers and then we will store them in two different variables for further operations. Step 2: Convert into Int type: To perform mathematical op erations on it, we first need to convert them into Int type as by default they are in string type. So now we need to use the int() function. Step 3: Doing the maths: Now let's perform the main four mathematical operations

#7 - Data Types

Image
Data Types Our next step is going to be Data Types. But first, let's know what are data types. What are data types? Programming uses a number of different data types. A data type determines what type of value an object can have and what operations can be performed. Remember, this is one of the most important things in coding and affects the functioning and output of code. Data types in Python In python, we have 14 different data types in 7 categories. Text Type: str Numeric Types: int ,  float ,  complex Sequence Types: list ,  tuple ,  range Mapping Type: dict Set Types: set ,  frozenset Boolean Type: bool Binary Types: bytes ,  bytearray ,  memoryview To get a data type of a value use type() function. ---------------------------------------------- code:- print(type(50)) output:- <class'int'> ----------------------

#5 - Variables - A box to our data

Image
Variables We just now wrote our first program but we will rarely output such hard-coded text. Mostly we output some data that is stored in a variable. So now let's learn about Variables . What are Variables? Variables are like containers containing a specific value that can be accessed anywhere in the code using the variable name. A variable name must start with a letter or an underscore ( _ ) and they are case-sensitive and can only contain alpha-numeric characters and underscores. Use an equal sign ( = ) to assign a variable. code:- output:- We are learning Python.

#4 - Hello World - Our first program using print function

Image
Print Function - Hello World Now, we have reached the excitement point when we will write our first program using the print function to output a text on the console. But first, let's understand what is a function. What is a function? In the easiest way, the function is a work that is to be performed on the data that is given inside the parenthesis that is in front of the keyword. Confused? Let's write a Hello World program to make you understand everything. We can also make our own custom functions which are called User-Defined Functions. Writing the code First, let's write and run the whole code and then understand everything. Open your VS Code and a python file to start writing code. If you don't know how to do it then it means surely you don't have read our post on how to setup VS Code and open a python file in it. Please click HERE to read it. Now, simply write print("Hello world!") and search for the run button (    ) and click it. You will find a

#6 - Arithmetic operators - Bringing maths in coding

Image
Arithmetic Operators Till now we have learned about print function and variables and going towards learning about arithmetic operators and how to implement them in our code. How to implement basic operators in the code? It's so simple to perform things like add, subtract, multiply and divide in python. We just have to use the symbols. ------------------------------------------------ code:- a = 5 b = 10 c = a + b print(c) output:- 15 ------------------------------------------------- Other operators in python are:- Operator Description Example + Addition Adds values on either side of the operator. a + b = 30 - Subtraction Subtracts right hand operand from left hand operand. a – b = -10 * Multiplication Multiplies values on either side of the operator a * b = 200 / Division Divides left hand operand by right-hand operand b / a = 2 % Modulus Divides left hand operand by right-hand operand and returns remainder b % a = 0 ** Exponent Performs exponential (power) calculation on operators

#3 - Which IDE? - Where to write our code?

Image
Which IDE? Now after we have installed python in our systems, we need to know that how can we code in python. For that, there should be a python file made in any of the folders and then we have to open the file in any  IDE(Integrated development environment).  Sounds confusing, right? But don't worry, everything will be easy very soon. First, let's understand what is an  IDE. What is an IDE? An  IDE(Integrated development environment)  is simply software that you can use to edit a code file. Notepad can also be used as a code editor. But the best 2  IDEs  for software development in python are Pycharm and Visual studio code. Pycharm is python specific but Visual studio is used for all languages and it is the most famous among all  IDEs  and is open-source software and offers you a great range of development tools . Here also you are suggested to go for Visual studio code as a beginner. How to install Visual studio code? To install  VS code (visual studio code)  is really a pie

#2 - Installing python in our system.

Image
Installation Hey! So let's start our journey. But for that, we need python to be there on our computers so we need to download it from the official site of python. Let's get started by installing python. Use the official site of python to download python. python.org/downloads What about the version? The latest version when this blog is being made is Python 3.9.1 but it may differ when you are reading this. Not to worry as there will be no major change in it so you can also go for the latest version you are getting. Do we need to set up any type of environment? One of the major advantage that python gives you is that it doesn't need any environment setup like other programming languages and all you need to do is to download and install it. So simply download the file and then run it. What next? Now we need to decide which IDE we want to use. In easy language, IDE is just a software that we use to write code in. There are many IDEs available and you can go for any. But it is

Popular posts from this blog

Comments

#1- Let's Learn Python In the least possible time

#9 - String Concatenation