+ 1
Valid email tester,
Okay so I made it like this, l = ["@", "."] c = 0 while True: inp = input(" Email: ") for i in l: c = c + 1 if inp != c or inp != c: print(" Invalid") else: inp == c and inp == c print("Your E-mail was " + inp + " and it is a valid email.") break How come it won't find the @ and the .?
12 Antworten
+ 2
Ok, so your for loop looks, in the first iteration, for an â@â, but it only looks in one place (i.e. in position âcâ). Maybe try something like this:
found_at = False
found_dot = False
for c in range(len(inp)):
if inp[c] == â@â:
found_at = True
if inp[c] == â.â:
found_dot = True
if found_at and found_dot:
print(âemail validâ)
else:
print(âemail invalidâ)
Iâm in a hurry so this is highly rudimentary but hopefully it should explain the point that you have to check every character of inp against @ and . not just one per iteration.
Also, currently what Iâve given you doesnât check that the @ comes before the .
Hooe thatâs at least some help.
+ 2
I gave it a shot with just one, and it's still not looking for the library?
for i in l:
c = c + 1
if inp [c] != i:
print(" Invalid")
else:
inp [c] == i
print("Your E-mail was " + inp + " and it is a valid email.")
break
How would I write it to look for the @ and . in my input?
Ex.
Enter an email address: mycoolname@myemail.com
Great, mycoolname@myemail.com is a valid email address!
Enter an email address: notmyemail
I'm sorry, notmyemail is not a valid email address
+ 2
thanks man im excited!
+ 1
There are a few issues here:
Youâre comparing the whole input (inp) to an integer (c), rather than individual characters of inp. You may need
if inp[c] != i:
or something like that since Iâm not completely sure how youâre designing your algorithm.
Definitely, though,
if inp != c or inp != c:
is superfluous as itâs the same test being conducted twice, and
inp == c and inp == c
is meaningless. Aside from it again being the same thing twice, inp == c is a comparison, but itâs not used in an if statement.
To answer your question about it not finding @ or . though, you have
for i in l:
which is correct, but youâve not used i in the code in your loop.
+ 1
Thank you Russ :D
+ 1
No worries. If you need any further help, Iâll see what I can do later on.
+ 1
f_a = False
f_d = False
while not f_a or f_d:
inp = input(" Email: ")
for char in inp:
if char == "@":
f_a = True
if char in inp:
f_d = True
if f_a and f_d:
print(" Your E-Mail " + inp + " was valid. ")
else:
print(" Try again. ")
I got it down :D thanks Russ,
now I know you can use True and False for finding memory logs in Python. How cool is that.
+ 1
Good stuff. Have you tested it?
+ 1
yes and works perfectly now to get to more addins
+ 1
i redid the whole code with my own, it wont work if there is only a @ in the input
Email: i@icom
Output: Try again
Email: @.
Output: Valid
+ 1
Ah ok. The code you posted above returns valid for i@icom.
Good work!
0
Are you sure? đ
Did you try inputting something like me@myaddress?
Not trying to nitpick, but I always like to know if someone finds a bug in my codes.