Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Saturday 2 May 2020

Last Stone Weight | Python

Code: class Solution: def lastStoneWeight(self, stones: List[int]) -> int: while(len(stones)>1): heaviest=max(stones); stones.remove(heaviest); heavier=max(stones); stones.remove(heavier); if(heaviest!=heavier): stones.append(heaviest-heavier); if(len(stones)==0): return 0; else: return stones[0];

Python for beginners: https://www.youtube.com/watch?v=egq7Z...

Telegram: https://t.me/clcoding_python https://www.facebook.com/pirawenpython/

Move Zeroes | Python

Code: class Solution: def moveZeroes(self, nums: List[int]) -> None: g=nums.count(0); i=0; while(i<g): nums.remove(0); nums.append(0); i=i+1;

Python for beginners: https://www.youtube.com/watch?v=egq7Z...

Telegram: https://t.me/clcoding_python https://www.facebook.com/pirawenpython/


Counting Elements | Python

Code :

class Solution: def countElements(self, arr: List[int]) -> int: output=0; for i in arr: if(i+1 in arr): output+=1; return output;
Python for beginners: https://www.youtube.com/watch?v=egq7Z..

Telegram: https://t.me/clcoding_python


Program to find whether a no is power of two or not | Python

Prerequisite: Data Type Conversion | Python | Castor Classes https://www.youtube.com/watch?v=z8yw6... Turn off the rightmost set bit | Python | Castor Classes https://www.youtube.com/watch?v=ol4VW... Relationship between binary representation of n & n-1 | Python | Castor Classes https://www.youtube.com/watch?v=iTxc9... Python for beginners: https://www.youtube.com/watch?v=egq7Z..

Telegram: https://t.me/clcoding_python

Escape Sequence in Python

Escape Sequence - 

Escape sequences are control character used to move the cursor and print characters such as ',".\ and so on.


















Friday 1 May 2020

Python Input() Function

Input( )

Python provides us the facility to take input from user using Input( ) function. This function prompts the user to input a value.

For example :

Name = input("Enter Your Name");
print(Name);

Output will be the name as entered by the user.

Let us take the example again:

name = input("Enter Your Name:");
print("Welcome Mr.",name);

Here suppose the user enter the name as "xyz Kumar" so the variable name will contain xyz Kumar. In such case the output of the program will be:

Output      Welcome Mr. xyz Kumar


 Please note that the input( ) accepts the input only in string format. so, if any mathematical calculation is to be performed, we need to convert the input to integer format. for converting the input to integer format Python provide us a function called :

Program without using int( ) function :

a = input ("Enter 1st Number:");
b =  input("Enter 2nd Number:");
c = a+b;
print("Addition =",c);

In this case if the value of a & b as given by user is 5 & 6 respectively then the output will be 56. As 5 & 6 will be treated as string and not integer.

Program using int( ) function

a = int(input("Enter 1st Number:"));
b = int(input("Enter 2nd Number:"));
c=a+b;
print("Addition=",c);

 In this case if the value of a & b as given by user is 5 & 6 then output will be 11 as we have converted the input from string to integer format.



Thursday 30 April 2020

Turn off the rightmost set bit | Python

Question: Write a program that unsets the rightmost set bit of an integer. Input: 12 Output: 8 Input: 7 Output: 6 Simple code: n=int(input()); print(n & (n-1)) Prerequisite: Data Type Conversion | Python | Castor Classes https://www.youtube.com/watch?v=z8yw6... Relationship between binary representation of n & n-1 | Python | Castor Classes https://www.youtube.com/watch?v=iTxc9... Python for beginners: https://www.youtube.com/watch?v=egq7Z..

Join: t.me/clcoding_python

Relationship between binary representation of n & n-1 | Python

Let's learn Python from basics.

Prerequisite:
Data Type Conversion | Python | Castor Classes
https://www.youtube.com/watch?v=z8yw67K8rC0 Python for beginners:
https://www.youtube.com/watch?v=nAWv9rGwGMQ&list=PLNhFkFk6qEgIq3lcbmxWIBFjEcq4lwRyk

Join: t.me/clcoding_python


Like us: https://www.facebook.com/pirawenpython/

Checking a number is Odd or Even using Bitwise Operators | Python

Prerequisite:
Bitwise Operation in Python | Castor Classes
https://www.youtube.com/watch?v=mqkBM9Nwy3k Python for beginners:
https://www.youtube.com/watch?v=nAWv9rGwGMQ&list=PLNhFkFk6qEgIq3lcbmxWIBFjEcq4lwRyk

Join: t.me/clcoding_python

#Code
e=10;
e%2==0

True

f=11;
f%2==0

False 

Like us: https://www.facebook.com/pirawenpython/

Tuple in Python | Part 2

Topics discussed in this video:
1)Accessing Elements of a Tuple
2)Creating New Tuples from Existing Tuples
3)Iterating Over Tuples
4)length of a Tuple
5)count how many times a specified value appears in a Tuple
6)find out the (first) index of a value in a Tuple
7)Checking if an Element Exists
8)Nested Tuples
9)Can we add or remove elements from a Tuple?

Prerequisite: Tuple in Python | Castor Classes https://www.youtube.com/watch?v=QJcs3... Python for beginners: https://www.youtube.com/watch?v=egq7Z...

Nested List & Matrix | List in Python | Part 7

Python for beginners: https://www.youtube.com/watch?v=egq7Z...

#Code to take Matrix input from user in Python
row=int(input("Enter the number of row:"));
column=int(input("Enter the number of columns:"));
l=[];
rs=[];
i=0;
j=0;
while i<row:
    while j<column:
        u=int(input());
        rs.append(u);
        j=j+1;
    l.append(rs);
    rs=[];
    j=0;
    i=i+1;
l



Wednesday 29 April 2020

Converting an Input String into a Floating Point Number | Python

List Traversal using while loop & break statement | Python

Code: mylist=[]; l=int(input()); i=0; while(i<l): m=int(input()); mylist.append(m); i=i+1; i=0; g=0; while(i<=l-2): es=mylist[i]; ms=mylist[i+1]; if(es==ms and ms==4): g=g+1; break; i=i+1; if(g==0): print(False); else: print(True);


Python for beginners: https://www.youtube.com/watch?v=egq7Z...

Int to String ,Float to String ,String to Int & String to Float conversion | Python

Topics covered: 1)Integer to String conversion 2)Float to String conversion 3)String to Integer conversion 4)String to Float conversion 5)Different way to concatenate string Python for beginners: https://www.youtube.com/watch?v=egq7Z...


Telegram: https://t.me/clcoding_python https://www.facebook.com/pirawenpython/ https://www.facebook.com/groups/piraw...

Stacks and Queues using List | Data Structures | Python

Topics discussed: 1)Stack using List 2)Queue using List Prerequisite: List in Python | Part 1 | Castor Classes https://www.youtube.com/watch?v=P2ogQ... List in Python | Part 2 | Castor Classes https://www.youtube.com/watch?v=vNxxQ... Python for beginners: https://www.youtube.com/watch?v=egq7Z...

Tuesday 28 April 2020

Tuple in Python

Topics covered: 1)Tuple 2)Packing 3)Unpacking 4)Swap two variables using Packing & Unpacking concept 5)Tuple with List Python for beginners: https://www.youtube.com/watch?v=egq7Z...



Web 🌐http://www.clcoding.com/ Telegram: https://t.me/clcoding_python https://www.facebook.com/pirawenpython/ https://www.facebook.com/groups/piraw..

Subtract the Product and Sum of Digits of an Integer | Python

Prerequisite:
Sum of Digits of a number | Python | Castor Classes
https://www.youtube.com/watch?v=IBK1-... Python for beginners:
https://www.youtube.com/watch?v=egq7Z...


Maximum 69 Number | Python

Check the problem statement here:
https://leetcode.com/problems/maximum... Prerequisite: List in Python | Part 6 | Castor Classes https://www.youtube.com/watch?v=kIpXn...

Factorials of large numbers | Python

In Python, value of an integer is not restricted by the number of bits and can expand to the limit of the available memory. Thus we never need any special arrangement for storing large numbers. Prerequisite: Loops in Python | Castor Classes https://www.youtube.com/watch?v=SZmbd


Popular Posts

Categories

AI (27) Android (24) AngularJS (1) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (117) C (77) C# (12) C++ (82) Course (62) Coursera (179) coursewra (1) Cybersecurity (22) data management (11) Data Science (95) Data Strucures (6) Deep Learning (9) Django (6) Downloads (3) edx (2) Engineering (14) Excel (13) Factorial (1) Finance (5) flutter (1) FPL (17) Google (19) Hadoop (3) HTML&CSS (46) IBM (25) IoT (1) IS (25) Java (92) Leet Code (4) Machine Learning (44) Meta (18) MICHIGAN (5) microsoft (3) Pandas (3) PHP (20) Projects (29) Python (748) Python Coding Challenge (221) Questions (2) R (70) React (6) Scripting (1) security (3) Selenium Webdriver (2) Software (17) SQL (40) UX Research (1) web application (8)

Followers

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