Valid email tester, | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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 .?

2nd Mar 2019, 3:07 PM
Ivan
12 Answers
+ 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.
2nd Mar 2019, 3:41 PM
Russ
Russ - avatar
+ 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
2nd Mar 2019, 3:30 PM
Ivan
+ 2
thanks man im excited!
2nd Mar 2019, 5:56 PM
Ivan
+ 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.
2nd Mar 2019, 3:23 PM
Russ
Russ - avatar
+ 1
Thank you Russ :D
2nd Mar 2019, 3:46 PM
Ivan
+ 1
No worries. If you need any further help, I’ll see what I can do later on.
2nd Mar 2019, 3:50 PM
Russ
Russ - avatar
+ 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.
2nd Mar 2019, 4:21 PM
Ivan
+ 1
Good stuff. Have you tested it?
2nd Mar 2019, 5:23 PM
Russ
Russ - avatar
+ 1
yes and works perfectly now to get to more addins
2nd Mar 2019, 5:44 PM
Ivan
+ 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
2nd Mar 2019, 5:53 PM
Ivan
+ 1
Ah ok. The code you posted above returns valid for i@icom. Good work!
2nd Mar 2019, 5:55 PM
Russ
Russ - avatar
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.
2nd Mar 2019, 5:50 PM
Russ
Russ - avatar