Posts

INFYTQ 2020|Programming logic

 Programming logic 1.     1.  .  Is Python case sensitive when dealing with identifiers? a) yes b) no c) machine dependent d) none of the mentioned   2.     2.  What is the maximum possible length of an identifier? a) 31 characters b) 63 characters c) 79 characters d) none of the mentioned   3.     3.  Which of the following is invalid? a) _a = 1 b) __a = 1 c) __str__ = 1 d) none of the mentioned   4.     4 .  Why are local variable names beginning with an underscore discouraged? a) they are used to indicate a private variables of a class b) they confuse the interpreter c) they are used to indicate global variables d) they slow down execution   5       5.  The value of the expressions 4/(3*(2-1)) and 4/3*(2-1) is the same. a) True b) False            

InfyTQ 2020|Coding questions

Coding questions   Question 1 (Even-Odd series):  Given a string and it contains the digits as well as non-digits. We have to find the count of non-digits. If it is odd then remove all the non-digits and print the string as in even-odd order.If it is even then print the string as in odd-even order. E.g.  The given string is  */24#5%7&9*3@ . We have to count the non-digit. It’s 7, odd. Then remove all the digits from the string and output will become (in a string) 254739. In the problem, we have only 2 even and 4 odd numbers then after the even number of completion print the remaining odd numbers. Solution:  This is a basic question and the time complexity is O(n) Python string = input ()  characters = [] even = [] odd = [] for i in string:      if i.isdigit():          if int (i) % 2 = = 0 :              even.append(i)          else :              odd.append(i)      else :          characters.append(i)      charlen = len (characters) minlen = min ( len (odd), len (even))