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