Monday, April 20, 2020

pie chart in seaborn library using python

import pandas as pd

# --- dataset 2: 3 columns and rownames
df = pd.DataFrame({'var1':[8,3,4,2], 'var2':[1,3,4,1]}, index=['a', 'b', 'c', 'd'] )

# make the multiple plot
df.plot(kind='pie', subplots=True, figsize=(16,8))




import pandas as pd
 
# --- dataset 2: 3 columns and rownames
df = pd.DataFrame({'var1':[8,3,4,2], 'var2':[1,3,4,1]}, index=['a', 'b', 'c', 'd'] )
 
# make the multiple plot
df.plot(kind='pie', subplots=True, figsize=(16,8))
Out[3]:
array([<matplotlib.axes._subplots.AxesSubplot object at 0x000001BBCAB27408>,
       <matplotlib.axes._subplots.AxesSubplot object at 0x000001BBCAB5E1C8>],
      dtype=object)
In [7]:
import pandas as pd
 
# --- dataset 2: 3 columns and rownames
df = pd.DataFrame({'var1':[4,4,4,4], 'var2':[1,3,4,1]}, index=['a', 'b', 'c', 'd'] )
 
# make the multiple plot
df.plot(kind='pie', subplots=True, figsize=(16,8))
Out[7]:
array([<matplotlib.axes._subplots.AxesSubplot object at 0x000001BBCB0BA6C8>,
       <matplotlib.axes._subplots.AxesSubplot object at 0x000001BBCB0E8F88>],
      dtype=object)
In [8]:
import pandas as pd
 
# --- dataset 2: 3 columns and rownames
df = pd.DataFrame({'var1':[4,4,4,4], 'var2':[1,3,4,1]}, index=['a', 'b', 'c', 'd'] )
 
# make the multiple plot
df.plot(kind='pie', subplots=True, figsize=(10,8))
Out[8]:
array([<matplotlib.axes._subplots.AxesSubplot object at 0x000001BBCB17E4C8>,
       <matplotlib.axes._subplots.AxesSubplot object at 0x000001BBCB315788>],
      dtype=object)
In [9]:
import pandas as pd
 
# --- dataset 2: 3 columns and rownames
df = pd.DataFrame({'var1':[4,4,4,4], 'var2':[2,3,4,1]}, index=['a', 'b', 'c', 'd'] )
 
# make the multiple plot
df.plot(kind='pie', subplots=True, figsize=(10,8))
Out[9]:
array([<matplotlib.axes._subplots.AxesSubplot object at 0x000001BBCB554DC8>,
       <matplotlib.axes._subplots.AxesSubplot object at 0x000001BBCB57DC88>],
      dtype=object)
In [ ]:
 

Friday, April 17, 2020

write a program to count lower and upper case letter in python

string=input("Enter string:")
count1=0
count2=0
for i in string:
      if(i.islower()):
            count1=count1+1
      elif(i.isupper()):
            count2=count2+1
print("The number of lowercase characters is:")
print(count1)
print("The number of uppercase characters is:")
print(count2)

output:
Enter string:this is anil kumar
The number of lowercase characters is:
15
The number of uppercase characters is:
0

capitalize each word in python

# Complete the solve function below.
def solve(s):
    if len(s)>0 and len(s)<1000:
        capital_words = s.title()       
        return capital_words

if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')

    s = input()

    result = solve(s)

    fptr.write(result + '\n')

    fptr.close()

output:
hello world
Hello World

LISP helloworld program

(write-line "Hello World")
(write-line "this is my first program")

output:
$clisp main.lisp
Hello World
this is my first program

Wednesday, April 15, 2020

design pattern example in python

n, m = map(int,input().split())
pattern = [('.|.'*(2*i + 1)).center(m, '-'for i in range(n//2)]
print('\n'.join(pattern + ['WELCOME'.center(m, '-')] + pattern[::-1]))

output:
  • ---------.|.---------
  • ------.|..|..|.------
  • ---.|..|..|..|..|.---
  • -------WELCOME-------
  • ---.|..|..|..|..|.---
  • ------.|..|..|.------
  • ---------.|.---------


textwrap using python

import textwrap

def wrap(string, max_width):
    return "\n".join([string[i:i+max_width] for i in range(0len(string), max_width)])

    

if __name__ == '__main__':
    string, max_width = raw_input(), int(raw_input())
    result = wrap(string, max_width)
    print result

leap year program using functions in python

def is_leap(year):
    leap = False
    
    # Write your logic here
    if year>= 1900 and year <=10**5:

        if (year % 4) == 0:
            if (year % 100) == 0:
                if (year % 400) == 0:
                     return True
                else:
                    return leap
            else:
                return True
        else:
            return leap
    

year = int(raw_input())
print(is_leap(year))

print a character and a string and sentence

#include <stdio.h>
#include <stdlib.h>


int main()
{
char a,a1[50],a2[100];
scanf("%c%*c",&a);
scanf("%s%*c",&a1);
scanf("%[^\n]",&a2);
printf("%c\n%s\n%s",a,a1,a2);
return 0;
}

output:
h
hello
how are you

h
hello
how are you

python class topic video