0

Help

what is wrong with my code????? try: name = input() n = 0 for i in name: n+=1 if n < 3 or n < 4: except: print('Invalid Name') else: print('Account Created') plz help

16th Apr 2021, 12:20 AM
Ailana
Ailana - avatar
3 Answers
+ 1
if n < 3 or n < 4: ( n < 4) will never be True without (n < 3) also being True, so this is weird. if you're wanting to trigger an exception on the if case, you want to "raise" the desired exception and put your except block at the end to catch it.
16th Apr 2021, 12:41 AM
Myk Dowling
Myk Dowling - avatar
+ 1
Use raise to create exception. n<4 is Logical Because it also includes n<3 name = input() n = 0 for i in name: n+=1 if n < 4: raise Exception('Invalid Name') else: print('Account Created')
16th Apr 2021, 1:07 AM
Amir
Amir - avatar
0
You put the try and except in strange places. I would not use then at all.
16th Apr 2021, 12:32 AM
Jerry Hobby
Jerry Hobby - avatar