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
  Using a For Loop to subtract numbers from an input function. Anunderling 9 2,821 Sep-22-2025, 08:56 PM
Last Post: deanhystad
  How to revert back to a previous line from user input Sharkenn64u 2 3,186 Dec-28-2024, 08:02 AM
Last Post: Pedroski55
  User input with while loops chizzy101010 2 12,610 Aug-25-2024, 06:00 PM
Last Post: chizzy101010
  WHILE LOOP NOT RETURNING USER INPUT AFTER ZerroDivisionError! HELP! ayodele_martins1 7 3,711 Oct-01-2023, 07:36 PM
Last Post: ayodele_martins1
  restrict user input to numerical values MCL169 2 2,564 Apr-08-2023, 05:40 PM
Last Post: MCL169
  Big O runtime nested for loop and append yarinsh 4 4,000 Dec-31-2022, 11:50 PM
Last Post: stevendaprano
  user input values into list of lists tauros73 3 2,911 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 3,132 Dec-25-2022, 03:00 PM
Last Post: askfriends
Question Take user input and split files using 7z in python askfriends 2 3,268 Dec-11-2022, 07:39 PM
Last Post: snippsat
  Code won't break While loop or go back to the input? MrKnd94 2 2,806 Oct-26-2022, 10:10 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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