Posts

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