-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalien_username.py
More file actions
40 lines (27 loc) · 881 Bytes
/
alien_username.py
File metadata and controls
40 lines (27 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# https://www.hackerrank.com/challenges/alien-username/problem
def CheckAlien(s):
if len(s) == 1:
return 'INVALID'
term = False
num = True
alpha = False
if s[0]!= '_' and s[0]!='.':
return 'INVALID'
if s[1].isnumeric() == False:
return 'INVALID'
if s[-1] == '_':
term = True
if not s[-1].isnumeric() and not s[-1].isalpha() and s[-1] != '_':
return 'INVALID'
for i in range(2,len(s)):
if not s[i].isnumeric() and not s[i].isalpha() and i < len(s)-1:
return 'INVALID'
if alpha and not term:
if s[i].isnumeric():
return 'INVALID'
if s[i].isalpha():
alpha = True
return 'VALID'
for _ in range(int(input())):
s = input()
print(CheckAlien(s))