simple e-mail without regexp and without list
-
Good evening. There's a question, I understand the point of error, but I can't find the right solution to the problem. The challenge is: Write an e-mail field holder using only the material that has been produced and the instruction that is in this task. Validator is a program that checks the correctness of the data. If the e-mail address is in place, remove YES, otherwise NO♪
Input data: email - string value
Output data: YES - if email is Validen, NO - unless email is Validen
Email field mask: @. - where ___ may contain a-z, A-Z, 0-9 and points. Each of the blocks shall contain at least one letter before the symbol @.
Regular expressions and lists cannot be usedI'm trying to set up a spontaneous rust and check that after @, the point is not the following symbol.
# Простой валидатор почтового адреса (без использования regual expression)
ввод строки пользователем
input_adr = input()
счетчик первого символа (проверяем есть ли в адресе хотя бы один символ)
inint_count = 0
верный адрес почты
correct_adr = 'alpaRist11@code.com'
поиск символов '.', '@' во входой строке
for i in input_adr:
at = '@'
dot = '.'проверяем наличие первого символа в строке, которую ввел пользователь
до символа @, первый блок
for inint_count in input_adr:
if((ord(input_adr[inint_count])>= 48 and ord(input_adr[inint_count])<= 57) or
(ord(input_adr[inint_count])>=64 and ord(input_adr[inint_count])<=90)
or (ord(input_adr[inint_count])>= 97 and ord(input_adr[inint_count])<= 122)):
inint_count += 1проверяем условия, что после символа @ идет хотя бы один символ,
что символы @ и . не идут вместе
if(inint_count > 0 and at > 0 and (dot-at) > 0 and (dot+1) < len(input_adr)):
print("Yes")
else:
print("No")In error:
File "main.py", line 20, in <module>
if((ord(input_adr[inint_count]>= 48) and ord(input_adr[inint_count]<= 57)) or
TypeError: string indices must be integers
-
if((ord(input_adr[inint_count]>= 48) and ord(input_adr[inint_count]<= 57)) or
Consider the brackets. You're getting the following.
ord(input_adr[inint_count]>= 48)
I mean, you.
ord
You're making it from a bell like that.ord(True)
orord(False)
Most likely you meant
ord(input_adr[inint_count]) >= 48
P. S.
And in fact, the code for the said rules, I would have done it like that:
address = 'test@A12.ru'
address_parts = address.split('@')
checked = address.count('@') == 1
проверить наличие точки
checked &= '.' in address_parts[1]
проверить наличие хотя бы одной буквы
checked &= any(letter.isalpha() for letter in address_parts[1])
проверить наличие букв, цифр и точки
checked &= all((letter.isalpha() or letter.isdigit() or letter == '.') for letter in address_parts[1])
ВНИМАНИЕ: в условии не сказано проверять блок до @, так что последнюю проверку можно удалить скорее всего
проверить наличие букв, цифр и точки
checked &= all((letter.isalpha() or letter.isdigit() or letter == '.') for letter in address_parts[0])
print(checked)
P.P.S.
If you can't use anything at all, you can use that code.
address = 'test@A14.ru'
checked = True
проверить кол-во символов @
symbols_count = 0
for i in address:
symbols_count += 1 if i == '@' else 0checked &= symbols_count == 1
найти координату '@'
symbol_pos = 0
for pos in range(len(address)):
if address[pos] == '@':
symbol_pos = pos + 1
breakпроверить наличие точки
isDot = False
for pos in range(symbol_pos, len(address)):
isDot |= address[pos] == '.'checked &= isDot
проверить наличие хотя бы одной буквы
isAlpha = False
for pos in range(symbol_pos, len(address)):
isAlpha |= ord('a') <= ord(address[pos]) <= ord('z') or ord('A') <= ord(address[pos]) <= ord('Z')checked &= isAlpha
проверить наличие букв, цифр и точки
isLetters = True
for pos in range(symbol_pos, len(address)):
isLetters &= ord('a') <= ord(address[pos]) <= ord('z') or ord('A') <= ord(address[pos]) <= ord('Z') or ord('0') <= ord(address[pos]) <= ord('9') or address[pos] == '.'checked &= isLetters
print(checked)
P.P.P.S.
The coke which evaluates not only the part after @ but also the separate blocks between the points in this part:
address = '@a.com'
checked = True
проверить кол-во символов @
symbols_count = 0
for i in address:
symbols_count += 1 if i == '@' else 0checked &= symbols_count == 1
найти координату '@'
symbol_pos = 0
for pos in range(len(address)):
if address[pos] == '@':
symbol_pos = pos + 1
breakпроверить наличие точки
isDot = False
for pos in range(symbol_pos, len(address)):
isDot |= address[pos] == '.'checked &= isDot
проанализировать блоки (расположенные между точками)
start = symbol_pos
for index in range(symbol_pos, len(address)):
if address[index] == '.' or index == len(address) - 1:
finish = index if address[index] == '.' else (index + 1)# проверить наличие хотя бы одной буквы isAlpha = False for pos in range(start, finish): isAlpha |= ord('a') <= ord(address[pos]) <= ord('z') or ord('A') <= ord(address[pos]) <= ord('Z') checked &= isAlpha # проверить наличие букв, цифр и точки isLetters = True for pos in range(start, finish): isLetters &= ord('a') <= ord(address[pos]) <= ord('z') or ord('A') <= ord(address[pos]) <= ord('Z') or ord('0') <= ord(address[pos]) <= ord('9') checked &= isLetters start = index + 1
print(checked)