Cloud Stack Ninja

Given a string, print whether it is a number, word, or mixed with digit and letters. If all the characters are numeric values, print NUMBER. If they are all letters, print WORD. If it is mixed, print MIXED.

value = 'nka121fsd132'
for i in range(len(value)):
  if ((ord(value[i])>=65 and ord(value[i])<=90) or
   (ord(value[i])>=97 and ord(value[i])<=122)):
    name="WORD"
  elif (ord(value[i])>=48 and ord(value[i])<=57):
    name="NUMBER"
  elif (((ord(value[i])>=65 and ord(value[i])<=90) or
  (ord(value[i])>=97 and ord(value[i])<=122)) or 
  (ord(value[i])>=48 and ord(value[i])<=57)):
    name="MIXED"
print(name)

Its printing NUMBER here,not mixed



Read more here: https://stackoverflow.com/questions/64408301/my-code-is-not-printing-mixed-value-while-logic-is-ascii-value-of-letters-and-nu

Content Attribution

This content was originally published by Kobra at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: