python question solution for fossee coding test

(Fosse python coding test question )Python program: Sneha inputs a string in function eg. ('nnbhccf') and two people asked to select one- one alphabet from Sneha's string when removing those two alphabet's every occurrence from the string if the result is less than half of the original string it returns false else true.



import random


def number_quiz(ls):
lstx = list(ls)
str_count = len(ls)
print(str_count)
a = random.choice(lstx)
b = random.choice(lstx)
print(a, b)
rem_lst = lstx.copy()
print("remlist", rem_lst)
for i in rem_lst:
if a in rem_lst:
rem_lst.remove(a)
rem_lst.remove(b)
else:
continue
lst_count = len(rem_lst)
print(rem_lst)
if lst_count < int(str_count/2):
print("you lose",lst_count)
else:
print("you win",lst_count)


if __name__ == '__main__':
print("enter your string:")
inp = input()
number_quiz(inp)


Comments