Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Nested Loop for user input
#1
Hello,

I am new to Python.
My code is like
age = int (input ("Enter your age = "))
name = input ("Enter your name = "))

if age > 15:
    if name == Albert:
       print ("You can login")
    else:
       print("you cant login")
It is giving error if user input for name anything other than 'Albert' as
Error:
NameError: name 'Albert' is not defined
Please guide.
Thanks
Ads
Reply
#2
"Albert" is a string so you must quote it. Now your program sees it as a variable and that variable is not defined.
Reply
#3
Thanks !

That I know and Albert condition is fine but when I put anything other Albert like Danny then it is giving me that error.
For Albert and age more than 15 message is displaying properly
but when I put age less than 15 and name other than Albert it is giving mentioned error in the message.

Thanks
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  WHILE LOOP NOT RETURNING USER INPUT AFTER ZerroDivisionError! HELP! ayodele_martins1 7 990 Oct-01-2023, 07:36 PM
Last Post: ayodele_martins1
  restrict user input to numerical values MCL169 2 869 Apr-08-2023, 05:40 PM
Last Post: MCL169
  Big O runtime nested for loop and append yarinsh 4 1,331 Dec-31-2022, 11:50 PM
Last Post: stevendaprano
  user input values into list of lists tauros73 3 1,023 Dec-29-2022, 05:54 PM
Last Post: deanhystad
Information How to take url in telegram bot user input and put it as an argument in a function? askfriends 0 1,026 Dec-25-2022, 03:00 PM
Last Post: askfriends
Question Take user input and split files using 7z in python askfriends 2 1,027 Dec-11-2022, 07:39 PM
Last Post: snippsat
  Code won't break While loop or go back to the input? MrKnd94 2 906 Oct-26-2022, 10:10 AM
Last Post: Larz60+
Sad how to validate user input from database johnconar 3 1,836 Sep-11-2022, 12:36 PM
Last Post: ndc85430
  Nested for loops - help with iterating a variable outside of the main loop dm222 4 1,531 Aug-17-2022, 10:17 PM
Last Post: deanhystad
  How to split the input taken from user into a single character? mHosseinDS86 3 1,137 Aug-17-2022, 12:43 PM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

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