Python Forum

Full Version: New Code
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
name1 = input('Please enter your name:  ')     
if name1 == str (anees) or str (clow) :
    print( 'Authentication Success, You are allowed to enter the premises ' )
else :
    print('Access not allowed')

# code to show who is allowed and who is not allowed to enter the premises #

When I run the code , its throwing error as name1 not defined . Please help

I am beginner to python coding, Please do help and rectify the code
(May-23-2021, 06:02 AM)r_anees Wrote: [ -> ]name1 = input('Please enter your name: ')
if name1 == str (anees) or str (clow) :
print( 'Authentication Success, You are allowed to enter the premises ' )
else :
print('Access not allowed')



# code to show who is allowed and who is not allowed to enter the premises #

When I run the code , its throwing error as name1 not defined . Please help

I am beginner to python coding, Please do help and rectify the code

name1 = input('Please enter your name: ')
if name1 == str ('anee') or str ('clow') :
    print( 'Authentication Success, You are allowed to enter the premises ' )
else :
    print('Access not allowed')
(May-23-2021, 06:02 AM)r_anees Wrote: [ -> ]When I run the code , its throwing error as name1 not defined .

Please paste the entire traceback and error message. For the code you've shown, that doesn't seem like an expected error.
(May-23-2021, 06:02 AM)r_anees Wrote: [ -> ]
name1 = input('Please enter your name:  ')     
if name1 == str (anees) or str (clow) :
    print( 'Authentication Success, You are allowed to enter the premises ' )
else :
    print('Access not allowed')

# code to show who is allowed and who is not allowed to enter the premises #

When I run the code , its throwing error as name1 not defined . Please help

I am beginner to python coding, Please do help and rectify the code

Hi there,

I'm a beginner too and thought I'd have a go. I got your code to work by using:

name1 = input('Please enter your name:  ')
if name1 == 'mal' or name1 == 'sally':
    print('Authentication Success, You are allowed to enter the premises')
else:
    print('Access not allowed')
There's probably better ways to do it, but that seems to work. Smile
Another way

#! /usr/bin/env python3

allowed_names = ['mal', 'sally', 'anees', 'clow', 'buddy', 'tom', 'denise']

name = input('Please enter your name: ')

if name.lower() in allowed_names:
    print(f'Authentication Success, {name.capitalize()}, You are allowed to enter the premises.')
else:
    print(f'Sorry, {name.capitalize()} is not in the allowed names list.')
Output:
Please enter your name: pop Sorry, Pop is not in the allowed names list. Please enter your name: anees Authentication Success, Anees, You are allowed to enter the premises.