Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
New Code
#1
Exclamation 
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
Yoriz write May-23-2021, 09:19 AM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
(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')
Reply
#3
(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.
Reply
#4
(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
Reply
#5
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.
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Forum Jump:

User Panel Messages

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