Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
name 'x' is not defined
#1
hi,
I keep getting errors regarding variable definition.
I did defined the variable, yet the visual studio still getting the error:
Error:
Exception has occurred: NameError name 'x' is not defined File "D:\Studies\Python\Ex_Files_Learning_Python_Upd\Exercise Files\Ch2\conditionals_start.py", line 10, in <module> if(x<y):
(the errors occurs at line 10)

the full code:
#
# Example file for working with conditional statements
#


def main():
    x, y = 1000, 100

    # conditional flow uses if, elif, else
if(x<y):
   st="x is less thay y"
else:
   st="x is grater thay y"


print(st)
    # conditional statements let you use "a if C else b"


if __name__ == "__main__":
    main()
Reply
#2
The indentation from line 10 is not inside of the main function.
dolev28 likes this post
Reply
#3
(Sep-28-2021, 09:49 AM)Yoriz Wrote: The indentation from line 10 is not inside of the main function.

Thank you. worked perfectly.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  python library not defined in user defined function johnEmScott 2 3,775 May-30-2020, 04:14 AM
Last Post: DT2000

Forum Jump:

User Panel Messages

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