Posts

Showing posts from June, 2020

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