Hi all,
My code is not working. Why?
print('enter your email for registration')
entered=input('your email is:')
if(entered=="",'@hotmail.com') or (entered=="",'@gmail.com') or (entered=="",'@yahoo.com'):
print('registration is successful. your email is :', entered)
else:
print('incorrect registration. you can use only hotmail, gmail or yahoo domain')
Please help. I am just learning.
if entered == '@hotmail.com' or entered == '@gmail.com' or entered == '@yahoo.com':
will do. but you can also do this:
if entered in ['@hotmail.com', '@gmail.com', '@yahoo.com']:
and if you dont want it to be case-sensitive:
if entered.lower() in ['@hotmail.com', '@gmail.com', '@yahoo.com']:
@
ezdev, thanks for the answer but code is still not working
in each case the answer is as follows
incorrect registration. you can use only hotmail, gmail or yahoo domain
not working is not very descriptive. If you get any error, post the full traceback in error tags.
actually code works, no error code but every answer:
incorrect registration. you can use only hotmail, gmail or yahoo domain
there is no "registration is successful. your email is :"
i know why. entered needs to be the part from the "@" onward to work with the code i gave you.
i would fix that with if entered.lower()[entered.index("@"):] (in place of entered.lower() from my previous example) though i would figure someone has a more elegant solution. it ought to solve your problem though.
.index("@") finds the position of "@" and [numeric:] gets the part from that position onward.
email=input('your email is:')
if email.endswith(('@hotmail.com', '@gmail.com', '@yahoo.com')):
print('registration is successful. your email is {}'.format(email))
else:
print('incorrect registration. you can use only hotmail, gmail or yahoo domain')
you may want to use a while loop and make user enter email till correct. Also checking user email address is better implemented via regex. your approach is simple and user may enter string that is invaid mail, but endswith correct domain
thank you for all answers. @
buran it works. have a nice sunday for all.