Posts

Showing posts from 2019

Pattern #2 on Python

Pattern #2 (Like Right angle Triangle) Hi Friends Welcome Yesterday we seen how to make left angle triangle pattern with star and given string. Here similarly we code for right angle triangle pattern   Output: (Input is 3 rows)   *  ** ***  ---- CODE: a = int(input('Enter number of rows: ')) for i in range(a):     n = a - i - 1     for j in range(a):         if n > j:             print(' ',end='')         else:             print('*',end='')     print() ------ By  PyKAR

Pattern #1 with input string on Python

Pattern #1 with input string Hi friends Welcome already we seen pattern #1 (Only star print) Today, similar pattern type,but there pattern format is given input Like if you give input is PyKAR, pattern is: ------- P Py PyK PyKA PyKAR ------ Similarly, you can give any input... CODE: b = input('Enter name: ') a = len(b) d = list(b) for  i in range(a):     for j in range(i+1):         print(d[j],end='')     print() ---- # This code for Reverse input pattern b = input('Enter name: ') a = len(b) c = '' for i in b:     c = i + c d = list(c) for  i in range(a):     for j in range(i+1):         print(d[j],end='')     print() ----- By PyKAR

Pattern # 1 On Python

Pattern # 1 Hi Friends Welcome back again Today we code for pattern  like (number of rows: 3) * ** *** above method pattern print by the getting input from user CODE: a = input("Enter number of rows: ") for i in range(int(a)):   for j in range(0,i+1):     print('*',end='')   print() ---- By PyKAR

Basic Calculator using Python

Basic Calculator using Python   Hello Friends Welcome today... Today we are create calculator using python code which is used to do addition, subtraction, multiply & division for only two numbers This is code is very easy... CODE: try:     n1 = float(input("Enter 1st number: "))     n2 = float(input("Enter 2nd number: "))     op = input("Enter operator number: ")     if op == "+":         print(n1 + n2)     elif op == "-":         print(n1 - n2)     elif op == "*":         print(n1 * n2)     elif op == "/":         print(n1 / n2)     else:         print("Invalid operator") except:     print("Invalid Input") ------- By PyKAR  

Jio - Money to PhoneNumber on Python

Jio - Money to PhoneNumber  It is a imagine not real.  Story: One day JIO owner (or anyone else) announced a price amount 1 crore to someone. But, he really confused to give to who (rather than employee or known person). So he decided to pick random phone number (Indian Number only) and give that amount rupees to the number. He asks computer to pick random number... ----- Come out of the story... We decide to code for that  Let's code... CODE: import random def phoneNumber():     ph = ''     for i in range(1):         n = random.randint(6,9)         ph += str(n)         for j in range(9):              c = random.randint(0,9)              ph += str(c)     print(ph) phoneNumber() ----- Note:   If you lucky, your number will be display.... ("You will get...

How do you find the largest and smallest number in an unsorted integer array? on Python

Q#3 Hi friends Welcome, we solve question number 2, here coding to solve another question. Question 2:         How do you find the largest and smallest number in an unsorted integer array?  We need input from user for array. But don't worry about it. Here Python code also do it for us randomly in every time. Let's Code and Check... CODE: import random a = [] while len(a) < 10:   ranAdd = random.randint(1,100)   a.append(ranAdd) print('Given Arrray: \n',a,'Total count: ',len(a)) max = a[0] min = a[0] for i in a:   if max < i:     max = i      if min > i:     min = i print('Maximum number from given array: ',max) print('Minimum number from given array: ',min) ---- By PyKAR

How do you find the duplicate number on a given integer array? On Python

Q#2 Hi friends Welcome, yesterday we solve question number 1, here solve another question Question 2:        How do you find the duplicate number on a given integer array? We need input from user for array. But don't worry about it. Here Python code also do it for us randomly in every time. Let's Code and Check... CODE: import random a = [] while len(a) < 100:   ranAdd = random.randint(1,100)   a.append(ranAdd) print('Given Arrray: \n',a,'Total count: ',len(a)) duplicate_num = [] temp = [] for i in a:   if i not in temp:     temp.append(i)   else:     duplicate_num.append(i) print('Given array removed from duplicate: \n',temp,'Total original count: ',len(temp))     print('Duplicate numbers: \n',duplicate_num,'Total duplicate count: ',len(duplicate_num)) ----- By PyKAR

Missing number in array from 1 to 100 - Python

Q#1 I found another interest interview question on some blog... ( https://simpleprogrammer.com/programming-interview-questions/ ) So, I decide to solve these question one by one by python Question 1:         How do you find the missing number in a given integer array of 1 to 100? We need input from user for array. But don't worry about it. Here Python code also do it for us randomly in every time. Let's Code and Check... CODE: import random a = [] while len(a) < 90:   ranAdd = random.randint(1,100)   if ranAdd in a:     pass   else:     a.append(ranAdd)    a.sort() print(a) missnum = [] for i in range(1,101):   if i in a:     pass   else:     missnum.append(i)      print(missnum) ------- By PyKAR

Anagram - Python Code

Anagram - Python Hi Friends Welcome, today we are coded for anagram. Anagram means " a word, phrase, or name formed by rearranging the letters of another, such as  spar , formed from  rasp . " arrangement doesn't matter. let's Code... CODE: from collections import Counter a = input('Enter string 1: ') b = input('Enter string 2: ') if Counter(a) == Counter(b):     print('Given String is Anagram') else:     print('Given String is not Anagram') ----- By PyKAR

Love Percentage - Python Code

Love Percentage Calculator Hi Friends Welcome, Today we are calculate love percetage with your favourite person This code very simple way... let's try... in your python console or our console in website top... CODE: from collections import Counter a = input('Enter your name: ').replace(' ','').lower() b = input('Enter your name: ').replace(' ','').lower() c = [i for i in a] d = [i for i in b] n = len(c) + len(d) d1 = Counter(c) d2 = Counter(d) c1 = list((d1 & d2).elements()) score = ((2 * len(c1)) / n) * 100 r = round(score,2) print(f'love Percentage with {b}: {r} %') ----- By PyKAR

Age Calculator

Age Calculator on Python Hi Friends Again one more program code i show you today... This code calculate your age as per given input as YOB Here, Method using import date function.. CODE: from datetime import date today = date.today() y = today.strftime("%Y") a = int(input('Enter your birth year: ')) age = int(y) - a print("Your age is",age) ----- By PyKAR

Check Given number add or even

add or even Hi Friends... Welcome today... I coded for given number is odd or even It is very simplest program compared to previous coded. okay let's start... CODE: try:     a = int(input('Enter any number: '))     if a > 0:         if a % 2 == 0:             print(f'{a} is a even number')         else:             print(f'{a} is a odd number') except:     print('Invalid input') ---- By PyKAR

Infinity Prime Number Calculation on Python

Infinity Prime Number Calculation on Python Hi friends Another Interesting program If you print prime numbers without stop... Solution is here Simple code make it for us... CODE: ---- a = 2 count = 1 while True:   for i in range(2,a+1):     if a % i == 0:       if a == i:         print(count,a)         count += 1       else:         break   a += 1 ---- By PyKAR

Least Common Factor - Python

Least Common Factor - Python Hi Friends Already we seen HCF Similar method and function here used to calculate LCM This method so simple... If you not seen my HCF code kindly visit as well. CODE: ----- # find LCM for two numbers from collections import Counter a = int(input('Enter first number: ')) b = int(input('Enter second number: ')) sum,a_f,b_f,sum1 = a,[],[],b while True:     for i in range(2,a+1):         if sum % i == 0:             sum = sum // i             a_f.append(i)             break     if sum == 1:         break while True:     for i in range(2,b+1):         if sum1 % i == 0:             sum1 = sum1 // i             b_f.append(i)             break     if...

Armstrong number - Range - Python

Armstrong number - Range - Python Hello Friends... Welcome today... I show you, how to find Armstrong number between range Easy code Let's see CODE 1: def armStrong(a):     n = len(str(a))     sum = 0     for i in str(a):         sum += pow(int(i),n)     return sum a = int(input('Enter range from 10 to: ')) arm = [] for i in range(150,a+1):     result = armStrong(i)     if result == i:         arm.append(i) print(arm) ---- CODE 2: # Check given code Armstrong or not def armStrong(a):     n = len(str(a))     sum = 0     for i in str(a):         sum += pow(int(i),n)     return sum a = int(input('Enter any number to check: ')) result = armStrong(a) if result == a:     print(f'{a} is a armStrong number') else:     ...

Highest Common Factor on Python

HCF on Python Hello Programmer's Welcome to my blog again.. Here i show you how to calculate "Highest Common Factor between Two numbers" on Python It interesting because when we attend an interview or exam, the question come, but we struggle to calculate the value if two numbers are big.. Here Problem is solve, You won't crush your brain... Simple code work for us... Okay..Let's see.. CODE : (Two Numbers) # find hcf for two numbers from collections import Counter a = int(input('Enter first number: ')) b = int(input('Enter second number: ')) sum,a_f,b_f,sum1 = a,[],[],b while True:     for i in range(2,a+1):         if sum % i == 0:             sum = sum // i             a_f.append(i)             break     if sum == 1:         break while True:     for i in range(2,b+...

Check Given number Prime or Not

Prime number - Check Hello Previous post we seen, how to print prime number Here we have to find given number is prime or not Let's code CODE: a = int(input('Enter number to check: ')) prime = False for i in range(2, a+1):     if a % i == 0:         if a == i:             prime = True         break if prime:     print(f'{a} is a prime number') else:     print(f'{a} is not a prime number') ---- By PyKAR

Prime Numbers On Python

Prime Numbers On Python Hello Every one welcome... Today i show you How to calculate prime number upto N th number Or How many prime numbers upto N th number Here make simple code If you like support us and also you find easier compare to it Post your code Okay Friends.,.. CODE 1: # Prime numbers a = int(input('Enter needed prime number range: ')) prime = [] for i in range(2,a+1):     for j in range(2,i+1):         if i % j == 0:             if i == j:                 prime.append(i)                 break             else:                 break print(prime) print(len(prime))  ------ CODE 2: # This another method using generators a = int(input('Enter needed prime number range: ')) def genr(a):   ...

Hackerrank Problem #2 On Python

Hacker rank Problem  Hello Guys, Welcome Today I solved Problem in Hackerrank website This problem I solved in my way Using for loop and if condition So Guys See my Code ... If anything else please point out and post your code if you solve very simple.... Question: Gary is an avid hiker. He tracks his hikes meticulously, paying close attention to small details like topography. During his last hike he took exactly    steps. For every step he took, he noted if it was an   uphill ,   , or a   downhill ,     step. Gary's hikes start and end at sea level and each step up or down represents a     unit change in altitude. We define the following terms: A  mountain  is a sequence of consecutive steps  above  sea level, starting with a step  up  from sea level and ending with a step  down  to sea level. A  valley  is a sequence of consecutive steps  below  sea leve...

BMI Calculation on Python Code

BMI Calculation Hi Programmer's Here We have make program for body mass index(BMI). It is just simple program...Not big one Okay Let's see.. CODE: a = int(input('Enter your weight in (kg): ')) b = float(input('Enter your height in (m): ')) bmi = a / (b*b) print(f'Your BMI: {bmi}') if bmi < 18.5:   print('You are under weight') elif 18.5 < bmi < 24.9:   print('You are normal weight') elif 25 < bmi < 29.9:   print('You are overweight') else:   print('Obesity') ----- By PyKAR

Fibonacci series

Fibonacci series Python We print Fibonacci series output on python Python makes everything easy.. Here Fibonacci series print by python.. Let's try... It will help to score in interviews.. CODE: ---- a = int ( input ( 'Enter number of fibonacci series: ' )) i = 0 x,y = 0 , 1 print (x) print (y) while i+ 2 < a: sum = x + y print ( sum ) x , y = y, sum i += 1 ---- You also use list to store all the output values... By PyKAR

Hackerrank Problems #1 solved in Python

Problems solved in Python Hackerrank Hello Programmer's Here i have submit question from hackerrank I solved this Check my code, Submit your code if you find easy and simple way. Copy that Py Code and Paste Below mention website and run it... website:  https://repl.it/languages/python3 The Utopian Tree goes through  2  cycles of growth every year. Each spring, it  doubles  in height. Each summer, its height increases by  1  meter. Laura plants a Utopian Tree sapling with a height of  1  meter at the onset of spring. How tall will her tree be after   growth cycles? For example, if the number of growth cycles is  , the calculations are as follows: Period Height 0 1 1 2 2 3 3 6 4 7 5 14 CODE 1: #!/bin/python3 import math import os import random import re import sys # Complete the utopianTree function below. def utopianTree(n): if ...

Create Multiple Folder on Python

Create Multiple Folder Python Hi Programmers.. Again i show interesting code to you.. Here I have show you how to create 'n' of folder {n - Depends on your wish, n means number} Copy that Py Code and Paste Below mention website and run it... website:  https://repl.it/languages/python3 CODE 1: from pathlib import Path i = 1 while i <= 10:     path1 = Path(f"dummy{i}")     print(path1.mkdir())     i += 1 CODE 2: Here we have create folder with name through array string value... ----- from pathlib import Path ar = ['raj','karthick','jack','sam','sasi'] n = len(ar) for i in range(n):     path1 = Path(ar[i])     print(path1.mkdir())      ------ Bonus: if you want create array with numbers of string, use below code ----- n = int(input()) ar = [] for i in range(n):     a = input()     ar.append...

CAR Start ... Stop Game in Python

CAR Start ... Stop Game Hello Progammers... Welcome tom this blog... This is simple program to start and stop car game, it will quite interesting. It's not very difficult So Let's try this on your console Copy that Py Code and Paste Below mention website and run it... website:  https://repl.it/languages/python3 Code ------------- print('Hi Racer...\nCome on and start your car...\nKindly follow your instruction to opeartor') print('start - start car\nstop - stop car\nquit - engineoff') off = True while off:     a = input().lower()     if a == 'start':         print('CAR Started.... :) ..>>>>')         while True:             b = input().lower()             if b == 'start':       ...

Count Swap for Sorting in Python

Count Swap for Sorting Hi Friends Here I have coding for how many swaps occur during sorting the list. I will help to score interviews.. So let's try and give your support.. Copy that Py Code and Paste Below mention website and run it... website:  https://repl.it/languages/python3 CODE 1: import sys n = int(input().strip()) a = list(map(int, input().strip().split(' '))) counter = 0 for x in range(len(a)-1): for y in range(x+1, len(a)): if a[x] > a[y]: a[x],a[y] = a[y], a[x] counter += 1 print('Array is sorted in', counter, 'swaps.') print('First Element:', a[0]) print('Last Element:', a[len(a)-1]) ---- By Pykar

Palindrome for check string On Python

PALINDROME Hi Friends.. Welcome to this blog I am PyKar Here i show you How to check given string is palindrome or not If you don't know about palindrome Google on it... Copy that Py Code and Paste Below mention website and run it... website:  https://repl.it/languages/python3 Here is this code I have make it with 2 different ways... CODE 1: import sys class Solution:     def __init__(self):         self.stack = []         self.queue = []     def pushCharacter(self, ch):         self.stack.append(ch)     def enqueueCharacter(self,s):         self.queue.insert(0,s)     def popCharacter(self):         self.stack.pop()     def dequeueCharacter(self):         self.queue.pop() s = input('Enter your string: ') obj = Solution() isPalindrome = True n = len(s) print(list_s) for i in ...

FLAMES CODE ON PYTHON

FLAMES Hi Friends Welcome to my blog... If you have a crush , You want to find what relations with your crush ... In my childhood days we are find it through " FLAMES " {'F- Friends', 'L-Lover', 'A-Affection', 'M-Marriage', 'E-Enemy', 'S-Sister'} So here i method we are not need to done on paper, Python Code will done it for us.. So Let's Start..... Copy that Py Code and Paste Below mention website and run it... website:  https://repl.it/languages/python3 from collections import Counter a = input('Enter your name: ').lower().replace(' ','') b = input('Enter your crush name: ').lower().replace(' ','') c = [] d = [] for i in a:   c.append(i) for i in b:   d.append(i) c1 = Counter(c) c2 = Counter(d) d1 = list((c1 - c2).elements()) d2 = list((c2 - c1).elements()) n1 = len(d1) n2 = len(d2) relations = ['F','L','A','M...