Posts

Showing posts from 2020

Hardy - Ramanujan Number (Magic Number) Program in Python

Hi Friends, Here I wrote a program to find ramanujan number though python programming  Support us to motivate me to write more program CODE: inp = 30000 for i in range(1,inp+1):     count = 0     for j in range(1,i+1):         if(pow(j,3) > i):             break         for k in range(j,i):             if(pow(k,3) + pow(j,3) > i):                 break             if(pow(k,3) + pow(j,3) == i):                 count = count + 1          if(count == 2):         print(i) ------- By PYKAR

Find Magic Number - Python

 Hi Friends, Here I solved magic number problem by python A number is said to be a magic number, if the sum of its digits are calculated till a single digit recursively by adding the sum of the digits after every addition. If the single digit comes out to be 1,then the number is a magic number CODE: def magic(n):   a = len(str(n))   sum = 0   for i in str(n):     sum += int(i)   if len(str(sum)) == 1:     return sum   else:     return magic(sum) a = int(input("Enter a range to find: ")) c = [] for i in range(1,a+1):   result = magic(i)   if result == 1:     c.append(i)    print(c) ------------- By PyKAR

How to find the first non repeated character of a given String?

How to find the first non repeated character of a given String? https://javarevisited.blogspot.com/2011/06/top-programming-interview-questions.html CODE: a = input("Enter a string: ") b = [] for i in a:     sum = 0     for j in a:         if i == j:             sum += 1             if sum > 1:                 break     if sum == 1:         b.append(i) if b:     print('"{}" is the first non repeated character'.format(b[0])) else:     print('None of char is non repeated')                             ---- By PyKar

How to count the occurrence of a given character in a String?

How to count the occurrence of a given character in a String? https://javarevisited.blogspot.com/2011/06/top-programming-interview-questions.html CODE: a = input('Enter a string: ') b = input('Which char need to find occurence: ') count = 0 for i in a:     if b == i:         count += 1 print(b,'character',count,'times occured in given string')       ----- By PyKAR

How to check if two String are Anagram?

How to check if two String are Anagram? CODE: a = list(input('Enter your 1st string: ').lower()) b = list(input('Enter your 2nd string: ').lower()) d = True for i in b:     try:         a.remove(i)     except:         d = False         print('Given string is not anagram')         break          if d:     if len(a) == 0:         print('Given string is anagram')     else:         print('Given string is not anagram')  ----- By Pykar

Pattern Right angle triangle

Input: KAR Output:       K    KA KAR CODE 1: a = list(input('Enter number of rows: ')) for i in range(len(a)):     n = len(a) - i - 1     k = 0     for j in range(len(a)):               if n > j:             print(' ',end=' ')         else:             print(a[k],end=' ')             k += 1     print() ----- Input: KAR Output:       R    AR KAR CODE 2: a = list(input('Enter number of rows: ')) for i in range(len(a)):     n = len(a) - i - 1     for j in range(len(a)):         if n > j:             print(' ',end=' ')         else:             print(a[j],end=' ')         ...

Write a method which will remove any given character from a String?

https://javarevisited.blogspot.com/2011/06/top-programming-interview-questions.html Write a method which will remove any given character from a String?  This one is second question solved by python CODE: a = input('Enter string word or sentence: ') b = input('Enter a remove word: ') c = a.replace(b,'') print(c) ---- Regards Pykar

Write code to check a String is palindrome or not?

This progrom is created for check given word is palindrome or not? https://javarevisited.blogspot.com/2011/06/top-programming-interview-questions.html First question solved by using python CODE: a = input('Enter your Word to check: ') n = len(a) b = -1 new_word = '' for i in range(n):     new_word = new_word + a[b]     b -= 1 if a ==  new_word:     print('Given word is palindrome') else:     print('Given word is not palindrome') ---- Regards PyKar

Find nth Prime Number in python?

Hi Friends Welcome Here i am coding for to find nth prime number? CODE: a = int(input("Which prime number(nth): ")) b = [] i = 2 while True:     for j in range(2,i+1):         if i % j == 0:             if i == j:                 b.append(i)             else:                 break     i += 1     if len(b) == a:         break print(str(a) + "th Prime number is: " + str(b[-1])) ------ Regards PyKAR

Fide Rating Calculate for Unrated

Image
Fide Rating Calculate for Unrated Player This is coding only to calculate rating for unrated player... So, Get your results from chess results and paste in txt file like show in below.... Then copy and paste these code in your py file and run it.... CODE: with open('rating.txt', 'r') as file:     result = [line.strip() for line in file] dp = {"0" : "800", "0.01" : "677", "0.02" : "589", "0.03" : "538", "0.04" : "501", "0.05" : "470", "0.06" : "444", "0.07" : "422", "0.08" : "401", "0.09" : "383", "0.1" : "366", "0.11" : "351", "0.12" : "336", "0.13" : "322", "0.14" : "309", "0.15" : "296", ...