Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Basic Python Question
#1
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.
Reply
#2
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']:
Reply
#3
@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
Reply
#4
not working is not very descriptive. If you get any error, post the full traceback in error tags.
Reply
#5
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 :"
Reply
#6
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.
Reply
#7
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
Reply
#8
thank you for all answers. @buran it works. have a nice sunday for all.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Basic Coding Question: Exit Program Command? RockBlok 3 553 Nov-19-2023, 06:31 PM
Last Post: deanhystad
  [solved] Basic question on list matchiing paul18fr 7 1,838 May-02-2022, 01:03 PM
Last Post: DeaD_EyE
  Very basic calculator question BoudewijnFunke 4 1,930 Dec-10-2021, 10:39 AM
Last Post: BoudewijnFunke
  Basic python Natters10 3 3,080 Nov-29-2020, 07:04 AM
Last Post: Love2code
  basic question isinstance tames 5 2,826 Nov-23-2020, 07:20 AM
Last Post: tames
  basic question about tuples and immutability sudonym3 6 2,896 Oct-18-2020, 05:11 PM
Last Post: sudonym3
  Basic Pyhton for Rhino 6 question about variables SaeedSH 1 2,139 Jan-28-2020, 04:33 AM
Last Post: Larz60+
  Help with basic python AaronG123 4 2,249 Nov-14-2019, 02:57 PM
Last Post: AaronG123
  Basic Beginner question NHeav 4 2,750 Sep-13-2019, 11:43 AM
Last Post: NHeav
  Basic coding question with Python Than999 3 3,099 Jul-17-2019, 04:36 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020