Friday, 31 December 2021

Happy New Year 2022 in Python using Turtle Library



Code:  



import turtle
turtle.setup(1000, 1000, 0, 0)
t = turtle.Turtle()
t.width(12)
t.color("maroon")
s = turtle.getscreen()
t.speed(2)
s.bgcolor("azure")
#clcoding.com
t.left(180)
t.penup()
t.forward(300)
t.right(90)
t.forward(100)
t.pendown()

t.forward(50)
t.right(90)
t.forward(50)
t.left(90)
t.forward(50)
t.left(90)
t.penup()
t.forward(50)
t.left(90)
t.pendown()
t.forward(50)
t.left(90)
t.forward(50)
t.right(90)
t.forward(50)

t.penup()
t.left(90)
t.forward(15)
t.pendown()
t.left(70)
t.forward(110)
t.right(70)
t.right(70)
t.forward(110)
t.left(180)
t.forward(55)
t.left(70)
t.forward(38)
t.left(70)
t.penup()
t.forward(55)
t.left(110)

t.forward(100)
t.left(90)
t.pendown()
t.forward(100)
t.right(90)
t.forward(50)
t.right(20)
t.forward(20)
t.right(70)
t.forward(40)
t.right(70)
t.forward(20)
t.right(20)
t.forward(50)
t.left(90)
t.forward(50)
t.left(90)
t.penup()
t.forward(100)

t.left(90)
t.pendown()
t.forward(100)
t.right(90)
t.forward(50)
t.right(20)
t.forward(20)
t.right(70)
t.forward(40)
t.right(70)
t.forward(20)
t.right(20)
t.forward(50)
t.left(90)
t.forward(50)
t.left(90)
t.penup()
t.forward(100)

t.forward(20)
t.pendown()
t.left(90)
t.forward(50)
t.left(30)
t.forward(60)
t.backward(60)
t.right(60)
t.forward(60)
t.backward(60)
t.left(30)

t.penup()
t.home()
t.color("blue")

t.backward(300)
t.right(90)
t.forward(60)
t.left(180)

t.pendown()
t.forward(100)
t.right(160)
t.forward(100)
t.left(160)
t.forward(100)

t.penup()
t.home()

t.backward(240)
t.right(90)
t.forward(10)
t.pendown()
t.forward(50)
t.left(90)
t.forward(50)
t.backward(50)
t.left(90)
t.forward(100)
t.right(90)
t.forward(50)
t.backward(50)
t.right(90)
t.forward(50)
t.left(90)
t.forward(50)
t.penup()
t.home()

t.backward(150)
t.right(90)
t.forward(60)
t.pendown()
t.backward(100)
t.forward(100)
t.left(120)
t.forward(40)
t.right(60)
t.forward(40)
t.left(120)
t.forward(100)
t.penup()
t.home()

t.backward(30)
t.right(90)
t.forward(65)
t.left(90)

t.pendown()
t.left(90)
t.forward(50)
t.left(30)
t.forward(60)
t.backward(60)
t.right(60)
t.forward(60)
t.backward(60)
t.left(30)

t.penup()
t.home()

t.forward(10)
t.right(90)
t.forward(10)
t.pendown()
t.forward(50)
t.left(90)
t.forward(50)
t.backward(50)
t.left(90)
t.forward(100)
t.right(90)
t.forward(50)
t.backward(50)
t.right(90)
t.forward(50)
t.left(90)
t.forward(50)
t.penup()
t.home()

t.forward(90)
t.right(90)
t.forward(50)
t.left(90)
t.pendown()
t.left(70)
t.forward(110)
t.right(70)
t.right(70)
t.forward(110)
t.left(180)
t.forward(55)
t.left(70)
t.forward(38)
t.left(70)
t.penup()
t.forward(55)
t.left(110)

t.forward(100)
t.penup()
t.home()
t.forward(180)
t.right(90)
t.forward(50)
t.left(180)
t.pendown()
t.forward(100)
t.right(90)
t.forward(50)
t.right(20)
t.forward(20)
t.right(70)
t.forward(40)
t.right(70)
t.forward(20)
t.right(20)
t.forward(50)
t.left(180)
t.forward(50)
t.right(20)
t.forward(20)
t.right(70)
t.forward(40)
t.left(180)
t.penup()
t.home()

t.right(90)
t.forward(215)
t.right(90)
t.forward(170)
t.color("green")
t.penup()
t.home()
t.home()
t.forward(370)
t.pendown()
t.color("magenta")
t.width(3)
t.speed(0)

def squre(length, angle):
    t.forward(length)
    t.right(angle)
    t.forward(length)
    t.right(angle)

    t.forward(length)
    t.right(angle)
    t.forward(length)
    t.right(angle)
squre(80, 90)

for i in range(36):
    t.right(10)
    squre(80, 90)

t.penup()
t.home()
t.left(90)
t.forward(270)
t.left(90)
t.forward(200)
t.pendown()

t.penup()
t.setpos(-270,-120)
t.pendown()
t.pencolor('red')
t.write('Happy New Year 2022 ',font=("Algerian", 24, "normal"))
turtle.mainloop()




Join us: https://t.me/jupyter_python

Monday, 29 November 2021

Numpy In Python

Introduction to NumPy

•   NumPy is a Python package and it stands for numerical python
•   Fundamental package for numerical computations in Python
•   Supports N-dimensional array objects that can be used for processing multidimensional data
•   Supports different data-types

Array

•   An array is a data structure that stores values of same data type
•   Lists can contain values corresponding to different data types,
•   Arrays in python can only contain values corresponding to same data type


NumPy Array


•   A numpy array is a grid of values, all of the same type, and is indexed by a tuple of 
nonnegative integers
•   The number of dimensions is the rank of the array
•   The shape of an array is a tuple of integers giving the size of the array along each dimension

Creation of array


To create numpy array, we first need to import the numpy package:




Some Operations on Numpy array











Join us: https://t.me/jupyter_python

Saturday, 27 November 2021

Sequence Data Part 5 | Day 9 | General Sequence Data Methods | Part I


General Sequence Data Methods | Part I


Some of the methods that we can apply on any sequential data.

So basically Python methods are like a Python function, but it must be called on an object.
And Python also has a set of built in methods that you can use on sequential data, but note that the method is going to written new values, but they are not going to change the original data at all. So we are going to look at few examples on how we can call the methods on the given sequential data
.





First I am creating a string for strsample which has a string to with that is learning is fun. So let
me first print and show you. So, the strsample contains string learning is fun.

String Methods


1) .capitalize() - So let us try to call some of the methods on the string but note here all string method returns new value. We do not change the original string. First we are going to look here is method capitalise and it is going to return the string with the first character capitalise. So let us just try this. So initially it was learning is fun and lowercase and now it is learning is fun with the upper case L.





2) .title() - Next one is title, basically capitalise the first character of each word. So if you have a sequence of values, if you have a string if you have set of strings in your data and if you want to do some of the operations like this then you can use all these methods on your string. So for example now, if you want to capitalise the first character of each word, then you can use title method in that case. So, it is going to written the values by capitalising the first character alone.





3) .swapcase() - And thus a method calls what case which is going to swap the
case of strings. So if it is a lowercase string then it is going to swap it to make it as uppercase string. So the original string had the learning is fun in all lowercase letters, but just what all the characters to uppercase.



4) .find()
And you can also find the index of a given letter, for example, if you want to particularly know the index of a given character then you can give that inside the find method. So that should be given the single quote. So the index of n is 4.




5) .count() - So if you want to count the total number of particular letter in a given string then you can use the count method. And inside the count method you can just give the desired string value. So that is one because a is present only ones. For example here is there in the word learning only once



6) .replace() - Using the method replace you will be able to replace any word with the given word. For example, you can apply or you can call that on the string and that is strsample and inside method you can just give string to be searched that is fun. So we are searching for the word fun in the strsample string and I am going to replace fun with joyful. So let me just try this. So you are getting learn is joyful. Instead of getting learn is fun which was the original string.




The below code will show all the functions that we can use for the particular variable:




len(object) returns number of elements in the object











Join us: https://t.me/jupyter_python

Friday, 26 November 2021

Java Oops Concept

Java Oops Concept:

1.       Objects

2.       Class

3.       Inheritance

4.       Polymorphism

5.       Abstraction

6.       Encapsulation

Object :

Any entity that has state and behaviour is known as an Object.

An object can be defined as an instance of a class.

Example :

Object = {property 1: value1, property 2: value 2……property n: value n}

Class :

  • Collection of object is called class.
  • It is a logical entity
  • Class doesn’t consume any space.
  • A class can also be defined as a blueprint from which you can create an individual object.

 

 

Inheritance :

When one object acquires all the properties and behaviours of a parent object, it is known as inheritance.

It provides code reusability.

It is a used to achieve runtime polymorphism.

 

Polymorphism :

If one task is performed in different way, it is known as polymorphism.

In java we use method overloading and method overriding.

 

Abstraction :

Hinding internal details and showing functionality is known as abstraction.

 

Encapsulation :

Binding or wrapping code and data together into a single unit are known as encapsulation.

Naming Convention :

1.     Class

    . It should start with the uppercase letter.

  It should be a noun such as Color, Button, System, Thread, etc.
Use appropriate words, instead of acronyms.

Example :

Public class Employee {

//code snippet

}

 

2.     Interface

It should start with the uppercase letter.

It should be an adjective such as Runnable, Remote, ActionListener.

Use appropriate words, instead of acronyms.

 

Example :

 

Interface Printable

{

//code snippet

}

3.     Method

It should start with lowercase letter.
It should be a verb such as main(), print(), println().
If the name contains multiple words, start it with a lowercase letter followed by an uppercase letter such as actionPerformed().

Example :

Class Employee

{

//method

Void get( )

{

//code snippet

}

}

4.     Variables

It should start with a lowercase letter such as id, name.

It should not start with the special characters like & (ampersand), $ (dollar), _ (underscore).

If the name contains multiple words, start it with the lowercase letter followed by an uppercase letter such as firstName, lastName.

Avoid using one-character variables such as x, y, z.

Example :

Class Employee

{

// variables

Int id;

Char name;

}

5.     Package

It should be a lowercase letter such as java, lang.
If the name contains multiple words, it should be separated by dots (.) such as java.util, java.lang.

Example :

Package com.abc.xyz;

Class employee

{

//code

}

 

6.     Constant

It should be in uppercase letters such as RED, YELLOW.

If the name contains multiple words, it should be separated by an underscore(_) such as MAX_PRIORITY.

It may contain digits but not as the first letter.

Example :

Class Employee

{

//constant

Static final int MIN_Age = 18;

//code

}

Object and class Example:

Public class Student {

Int id ;

String name;

Public static void main (String[] args)

{

Student s1 = new Student();

System.out.println(s1.id);

System.out.println(s1.name);

}

}

Syntax of class :

Class <class_name>{

Field;

Method;

}

 

Class Student {

Int rollno;

String name;

Void insertRecord(int r, String n)

{

Rollno = r;

Name = n;

}

Void display()

{

System.out.println(rollno+ “ “ +name);

}

Class StudentTest {

Public static void main (String[] args)

{

Student s1 = new student();

Student s2 = new Student();

S1.insertRecord(101, “Ram”);

S2.insertRecord(102, “Sita”);

S1.display();

S2.display();

}

}

 

Class Student {

Int id;

String name;

}

Class StudentTest {

Public static void main (String arg[])

{

Student s1 = new Student();

Student s2 = new student();

S1.id = 101;

S1.name = “Ram”;

S2.id = 102;

S2.name = “Sita”;

System.out.println(s1.id+ “ “ s1.name);

System.out.println(s2.id+ “ “ s2.name);

}

}

Sequence DataType Part - IV [Concatenation and Multiplication]

Sequence Data Operations : Concatenation

Syntax : '+' , '+='


Now we will learn some of the most fundamental sequence data operation that is concatenation and multiplication. So, this will be helpful when you are looping over your looping over elements in your containers. So, now we will learn some of the most fundamental sequence data operations that is concatenation and multiplication which can be applied on to any sequential data.

 So, we are going to do concatenation using the plus operator. And there are a few ways of doing this depending on what you are trying to achieve and the simplest and the most common method is to use the plus symbol to add multiple strings together or to add multiple elements together it can be applied onto any sequential data as well. And simply place a plus between as many as simply place a plus between as many strings as you want to join together. So, let us see an example to do that. So, for example, so, we know what is there under strsample it just has a word learning.






So, this is the original list that we have 1 2 a sam 2 and in the next line I am concatenating the list to the existing list lstsample and the list contains a string that is p y I am giving that inside the square bracket because you will be able to concatenate to list. So, if you can see here the py list has been added as has been added as an element to the existing list that is lstsample. So, we do not have a separate list which contains a py string rather it has been added or gets updated in the original list itself or gets updated as a last element in the original list itself. 





And let us see an example on how we can concatenate the arrays let us see an example whether we will be able to concatenate two different sequence data for example let us try an example to concatenate the list and the arrays together. So, first let us see what is there under the array that it has basically values one two three and four which are of integer data type and by using a plus operator I am going to concatenate a list together I am going to concatenate a list to the existing array




So, it basically throws you what traceback errors it basically throws you a type error saying that it can only append array to list it cannot append array to a. So, the type error is throwing basically it saying can only append array to array not list to array. So, we because we are trying to concatenate or we are trying to append the list to an existing array that is not possible. So, what we have to do here means if you want to concatenate to an array





If you want to concatenate a sequence data to an array then that sequence data should be of the same kind that is array. So, what we can do here is we can use the same values but just put them as array basically using the array function and keeping the data type as integer and giving the values as array and giving the values as list inside the array. Array sample will get concatenated with the given values that is 50 and 60 since you created it as array and then concatenated.







So, the next one is concatenation on concatenating two tuples together. So, here if you can see here I have just used plus and equal to then it means that I am going to add a new tuple to the existing tuple, tupsample and that is automatic glue and that gets updated in the tupsample itself. So, the tupsample basically had 1, 2, 3, 4 and py and I have added th, on separately as a and I have added a new tuple having two strings th and on. So, and that get add and that gets added to the existing tupsample and that gets updated on the existing tuple sample because I have given plus and equal to.








Join us: https://t.me/jupyter_python 

Wednesday, 24 November 2021

Sequence DataType Part - III [Slicing]



Sequence data operations: Slicing


•   The slice() constructor creates a slice object representing the set of indices specified by 
range(start, stop, step)
•   Syntax: slice(stop), slice(start, stop, step)
•   If a single parameter is passed, start and step are set to None

So, let us get started with slicing. So, the slice object is used to slice a given sequence and the
sequence can be string the sequence can be strings tuples, bytes, list or range or any object which
supports sequence protocol. And the slice object represents the indices specified by the range
function given the start stop and the step value. And the syntax of the slice operation the syntax
for the slice object is given here and the syntax for the slice function is given here.

So, you can either use slice of stop or you can use slice of start stop and step. So, basically the
slice function takes in three arguments which have the same meaning in both the constructs. So,
the first one is start which is a starting integer value where the string which is an integer value
which is an integer value which represents the starting from where the slicing of the objects.






So, the first argument is start. So, that is the starting integer where the slicing of the object starts
the next one is top that is an integer until which the slicing takes place. So the slicing stops at the
index n minus 1 or the minus 1.. So, for example I have given the second argument as 4 it means
that is the stop value. So, it is going to give me the sequence of values still 3. So, next one is step
an integer value which determines the increment between each index for slicing.

So, for example if you are giving 2, so, you will fetch the, so, you will be getting the values in
the step size 2. So, by default if you do not give anything it is going to take it as 1 as the
increment value but if you are providing any value then it is going to consider that as the
increment value.


String Slicing 






So, let us just get started with the example on string. So, we have already
created the string called strsample which has a string called learning. So, now my objective is to
get the substring from a given string strsample from the given string learn from the given string
learning.

So, we can use the slice object to do that. So, on strsample I am using the slice of I am using the
slice function inside the square brackets then inside the slice function I am just giving three
values one for start stop and the step value. So, here the output I have already printed that is er
which is e and r from learning. So, basically we have got that by specifying the starting index as
one. So, actually the slicing started from e and it will actually end at the index 4 then it is 2 3 and
4.

So, n will have the index 4 but actually it is going to give you till n minus 1 right. So, it will stop
at r and since I have given the increment value as 2 it is not going to give you all the sequence of
sequence of strings from e as it is not going to give you the sequence of strings as e a r rather it is
going to give you the sequence in terms of incrementing the strings by two. So, it is just going to
give you as a r alone.

So, it is just going to give you the output as e r alone. So, this is how the slicing operator. So, this
is how we use the slice function in order to slice the given sequence of elements or given
sequence of substrings from the given string or the any sequence object. And the other method is
the other method for slicing the elements or the substrings from a given object is using the square
bracket. You do not have to use the slice function inside it you can either use the slice function or

the colon operator.

Here I am using just a colon inside the square bracket. So, that it gives me all the substrings from
a string learning that is learning. So, just by giving just by just placing colon inside the square
brackets fetches me the learning that is the complete set of strings from the main string that is
strsample. So, this is how we perform the slicing on the string sequence data. So, basically we
use slicing whenever we want to perform any operations on a particular set of elements on your
string or on your any or it can be applied on any sequence data.

So, all the values from a list will not get modified based on your calculation or based on your
operation only the particular set of elements or substrings will be modified based on the
operations that you are performing on it.


List Slicing




it. Similarly we can perform the slicing operations in other
in any other sequence data for example the next example to illustrate you is on list. So, lists
basically have a default bit of functionality when slicing.

So, here let us just print what is there under the list sample so these are the values these are the
elements that is there under the lstsample 1 2 a sam and 2. So, now I am going to perform slicing
on the list sample. So, basically if there is no volume before the first colon for example like this I
have not given any value before the first colon and I have given value after the colon in that case
it needs to start at the beginning index of the list.

It means to start the slicing at the beginning index of the list. So, let us just see what happens
when we use colon 3. So, the output is given here. So, this the slicing started from the index 1.
So, the slicing started from the beginning of the list that is from 1 itself and the next value is the
stop value. So, 0 1 2 3 it is going to give you the sub elements from the list till or before sam. So,
we have got the output as 1 2 and a.

Since the index the since the stop index is at 3 it is just going to give you a value it is just going
to give you a sequence of elements or sequence of sub elements from your main list which is just
before the third index that is 1 2 and a. The other thing to note here if you have not provided a
value after the first colon like this then it means to go all the way to the end of the list starting

from the index 2. So, I am just saying to slice starting from the index 2 and to go all the way to
the end of a list and this basically saves this time.

So, that we do not have to manually specify length of a which basically. So, this saves us time.
So, that we do not have to manually specify length of len of lstsample in order to specify that is
the end of a list or that is to specify the that is to specify or to check how many elements are
there in a list. So, in order to get rid of that you can just use a colon after the you can you do not
have to specify anything after the first column. So, that it automatically takes all the sub elements
till the end of your list. So, this is how we perform the slicing operation on a list.

So, here if you have noted down I have not used the slice function rather I have just used the
colon operator to slice the sub elements from the list by just separating by just giving the start
stop and the step value in terms of using colon operator. And if you can recall here whatever
order that you are giving here inside the slice option inside the slice function the same applies
here but instead of using slice function I have just used the square bracket.

And if I give 2 colon 3 colon 1 then it means that starting while the starting index is 2 and the
ending index is 3 and the increment value is 1 but you can as well specify without even giving
any value just to denote that I need all the values from 2 and I need all the values till 3.
(Refer Slide Time: 09:54)

For example this is the start value and the stop value let us check what is the output? So, the
slicing operation is being done from the index 2 of the list that is 0 1 2 from a until 4 3 and 4 and
it is not going to consider the 4 as the index but it just considered till n minus 1. So, that will be
3. So, it is going to give you a and sam as the output. So, I hope this is clear. So, let us move on
to performing the slicing on the other sequential data.

Dictionary Slicing



So, we have also created a dictionary sample right so let us just perform slicing on it but it gives
you an error saying type error and hashable type that is slice. So, if you can recall the python
dictionary object provides a key value indexing facility and the values in the dictionary are
indexed by keys and they are not held in any order in that case we will not be able to perform
slicing because it requires the index to slice the given sequence of values or given sequence of
elements.

To slice the sequence of values or sequence of keys from your dictionary, so, slice. So, we
cannot perform slicing on a dictionary because it is a non it is a container for non it is a container
for holding non sequential data.


Set Slicing




So, in that case we will not be able to apply that onto a set as well. So, let us just see what happens when we apply that onto a set. So, it also throws an error
saying set object is not subscriptable.

As we know that set is also a container to hold non-sequential data. So, all the elements inside
the set are not indexed or not indexed by any indices rather they are not they are not held in any
order. So, we cannot perform the slicing operation on a set also because even set is also a
container for holding the non-sequential data in that case all the elements inside the set will not
have any index for index corresponding to each element. So, we can perform the slicing in index
as well.




Join us: https://t.me/jupyter_python

Popular Posts

Categories

AI (32) Android (24) AngularJS (1) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (146) C (77) C# (12) C++ (82) Course (67) Coursera (198) Cybersecurity (24) data management (11) Data Science (106) Data Strucures (8) Deep Learning (13) Django (14) Downloads (3) edx (2) Engineering (14) Excel (13) Factorial (1) Finance (6) flask (3) flutter (1) FPL (17) Google (21) Hadoop (3) HTML&CSS (47) IBM (25) IoT (1) IS (25) Java (93) Leet Code (4) Machine Learning (46) Meta (18) MICHIGAN (5) microsoft (4) Nvidia (1) Pandas (3) PHP (20) Projects (29) Python (888) Python Coding Challenge (285) Questions (2) R (70) React (6) Scripting (1) security (3) Selenium Webdriver (2) Software (17) SQL (42) UX Research (1) web application (8)

Followers

Person climbing a staircase. Learn Data Science from Scratch: online program with 21 courses