+ 1
Someone plz help me out... Tried to solve it... But didn't get the output.
You are making a registration form for a website. The form has a name field, which should be more than 3 characters long. Any name that has less than 4 characters is invalid. Complete the code to take the name as input, and raise an exception if the name is invalid, outputting "Invalid Name". Output "Account Created" if the name is valid. Sample Input: abc Sample Output: Invalid Name
25 Respostas
+ 8
try:
name = input()
if len(name)<4:
raise NameError
except:
print("Invalid Name")
else:
print("Account Created")
+ 2
try this code i think this might help
try:
name = input()
#your code goes here
if len(name) < 4:
raise Error
else:
print("Account Created")
except:
print("Invalid Name")
+ 1
Sandeep Kushwaha Thank you so much for your answer.
+ 1
Use this code, I think this is simple code
try:
name = input()
if len(name) > 3:
print ("Account Created")
else:
raise NameError
except:
print("Invalid Name")
+ 1
try:
name = input()
#your code goes here
if len(name)<4:
raise NameError
except:
print("Invalid Name")
else:
print("Account Created")
+ 1
name = input()
if (len(name) < 4):
print("Invalid Name")
else:
print("Account Created")
Thank me later... surprisingly this works
0
Niviedha shekor Show your attempt
0
try:
name = input()
#your code goes here
if name==(str(len >=4)):
raise("Account Created")
except:
print("Invalid Name")
0
Posted my attempt above
0
Niviedha shekor Invalid syntax error
0
Have also tried this coding
name = input()
try:
name == (str(len <= 3))
raiseexception("InvalidName")
except:
print("Account Created")
0
Niviedha shekor raise Exception use like this
https://code.sololearn.com/c4IcASq8JG89/?ref=app
Check it
0
you are comparing name with stringified boolean, while you are supposed to compare name.length to boundary (3-4), plus you don't need try/except:
name = input()
if len(name) < 4:
raise Exception('Invalid Name')
else:
print('Axcount Created')
0
try:
name = input()
#your code goes here
if len(name)<4:
raise NameError
except:
print("Invalid Name")
else:
print("Account Created")
0
try:
name = input()
#your code goes here
if len(name)<4:
raise NameError
except:
print("Invalid Name")
else:
print("Account Created")
0
try:
name = input()
#your code goes here
if len(name) < 4:
raise Error #raise statement
else:
print("Account Created")
except: #except statement
print("Invalid Name")
0
try:
name = input()
#your code goes here
if len(name)<4:
raise NameError
except:
print("Invalid Name")
else:
print("Account Created")
0
try:
name = input()
#your code goes here
if len(name)<4:
raise NameError
except:
print("Invalid Name")
else:
print("Account Created")
0
try:
name = input()
#your code goes here
if len(name)<4:
raise NameError
except:
print("Invalid Name")
else:
print("Account Created")
0
try:
name = input()
if len(name)<4:
raise NameError
except:
print("Invalid Name")
else:
print("Account Created")