What Is A Syntax Error In Python?

Sdílet
Vložit
  • čas přidán 13. 09. 2024

Komentáře • 38

  • @StudySessionYT
    @StudySessionYT  Před 4 lety +2

    My recommended book for learning Python: Python Crash Course, 2nd Edition: A Hands-On, Project-Based Introduction to Programming.
    Amazon Affiliate link to support us here at StudySession: amzn.to/2G9pFVA

  • @korosheht5446
    @korosheht5446 Před 3 lety +13

    Wait its not possible
    Some one actually just explained the question and said goodbye without talking about history of how python got created

  • @unjinjang2234
    @unjinjang2234 Před 3 lety +2

    Simple and Precise explanation. Thanks a lot!

  • @saeeda.495
    @saeeda.495 Před 3 lety +1

    fruit = {"orange": "a sweet, orange, citrus fruit"
    "apple": "good for making cider",
    "lemon": "a sour, yellow cistrus fruit",
    "grape": "a small, sweet fruit growing in bunches",
    "lime": "a sour, green cistrus fruit"}
    # print(fruit)
    # print (fruit["lemon"]
    # fruit ["pear"] = "An odd shaped apple"
    # print(fruit)
    # fruit ["pear"] = "great with cider"
    # print(fruit)
    print(fruit)
    while true:
    dict_key = input ("please enter a fruit: ")
    if dict_key == "quit":
    break
    description = fruit.get(dict_key)
    print(description)
    print(fruit)
    veg = {"cabbage": "every child's favorite",
    "sprouts": "mmmm, lovely",
    "spinach": can I have some more fruit please"}
    print(veg)
    veg.updae(fruit)
    print(veg)
    print(fruit.update(veg))
    print(fruit)
    I've tried writing this code again and again, still it gives me an Syntax error...

  • @shivamtanwar2649
    @shivamtanwar2649 Před 3 lety +2

    How do find the syntax error?

    • @StudySessionYT
      @StudySessionYT  Před 3 lety +1

      If you're using an IDE (like PyCharm for example), it will explicitly tell you there is a syntax error on line 5 for example!

  • @abineshdhoni9851
    @abineshdhoni9851 Před 2 lety +1

    I write the simple code like
    A=int(input("Enter your Age:")
    if A>=18
    print ("You are eligible for voting")
    else
    print("You are not eligible for voting")
    But it shows syntax error
    What could I do?

    • @yfvbmj
      @yfvbmj Před 2 lety +1

      you did not add the colon after else
      else:
      print("you are eligible for voting"")

  • @walewale7401
    @walewale7401 Před 3 lety +2

    i have a question
    i have a syntax error and python keeps on hightlighting my colon even though im doing an if else statement. do you know what error this is

    • @StudySessionYT
      @StudySessionYT  Před 3 lety +1

      Could you copy the text and paste it here so that I can better help you solve the problem?

    • @StudySessionYT
      @StudySessionYT  Před 3 lety

      ted1 = input(“How marks did you get on your test out of 100? “)
      ted2 = int(ted1)
      if ted2 < 10:
      print(“U”)
      elif 10 < ted2 < 20:
      print(“1”)
      elif 30 < ted2 < 40:
      print(“2”)
      elif ted2 == 100:
      print(“10”)
      else:
      print(“ERROR”)
      If you need any further explanations let me know :)

    • @walewale7401
      @walewale7401 Před 3 lety +2

      @@StudySessionYT thank you very much I've been stuck on it for a while😁😊

    • @StudySessionYT
      @StudySessionYT  Před 3 lety

      @@walewale7401 no problem, glad I could help!

  • @hoboloath
    @hoboloath Před 4 lety +1

    i am getting a syntax error when trying to add a variable to a dictionary.
    dog = {
    'name': 'kirby',
    'hungry': True,
    'weight': 9.5,
    'age': 10,
    'photo': ("^0-0^")
    }
    all of the above variables appear to be working fine but when i add
    'health': 100,
    it says i have a syntax error. im confused because it is following the same structure as the previous.

    • @StudySessionYT
      @StudySessionYT  Před 4 lety +2

      Are you adding that to the end of your dictionary? I’m just wondering if you have the extra comma on the end that is not needed?

  • @boozt6756
    @boozt6756 Před 2 lety

    Hi, I would like help with this, it shows syntax error everytime.
    print("Superhero Quiz")
    print("3,2,1.....START")
    print("Question 1, What is Superman's real name?")
    print("Your options are n/")
    print("Option A,Clark Kent")
    print("Option B, Kent Clark")
    print("Option C, Tony stark")
    print("Option D, Kal-El")
    AnswerA=int(input(" Please Enter your option's alphabet you have chosen as your answer")
    if AnswerA==1:
    Mark=Mark+1
    else:
    Mark=Mark+0

  • @smellysmall2262
    @smellysmall2262 Před 2 lety +1

    BRUV DIDNT EVEN ADDRESS HOW TO FIX ANY

  • @hamzahimran3447
    @hamzahimran3447 Před 3 lety +1

    """
    Mad Libs is a phrasal template word game which consists of one player prompting others for a list of words to substitute for blanks in a story before reading aloud.
    Author: Hamzah I
    """
    print ("Mad Libs is starting!")
    name = input("Enter a name: ")
    first_adj = input("Enter an adjective: ")
    second_adj = input("Enter a second adjective: ")
    third_adj = input("Enter one more adjective: ")
    first_verb = input("Enter a verb: ")
    second_verb = input("Enter a second verb: ")
    third_verb = input("Enter one more verb: ")
    first_noun = input("Enter a noun: ")
    second_noun = input("Enter a second noun: ")
    third_noun = input("Enter a third noun: ")
    fourth_noun = input("Enter one more noun: ")
    animal = input("Enter an animal: ")
    food = input("Enter a food: ")
    fruit = input("Enter a fruit: ")
    number = input("Enter an number: ")
    superhero_name = input("Enter a superhero name: ")
    country = input("Enter a country: ")
    dessert = input("Enter a dessert: ")
    year = input("Enter a year: ")
    STORY = "This morning I woke up and felt %s because %s was going to finally %s over the big %s %s. On the other side of the %s were many %ss protesting to keep %s in stores. The crowd began to %s to the rhythm of the %s, which made all of the %ss very %s. %s tried to %s into the sewers and found %s rats. Needing help, %s quickly called %s. %s appeared and saved %s by flying to %s and dropping %s into a puddle of %s. %s then fell asleep and woke up in the year %s, in a world where %ss ruled the world."
    print STORY % (first_adj, name, first_verb, second_adj, first_noun,
    second_noun, animal, food, second_verb, third_noun, fruit,
    third_adj, name, third_verb, number, name, superhero, superhero,
    name, country, name, dessert, name, year, fourth_noun)
    can y’all find the syntax error in this?

    • @StudySessionYT
      @StudySessionYT  Před 3 lety +1

      The easier way to do this would be using a f-string (if your python is updated), here is a quick video on what they are and how to use them!
      Link: czcams.com/video/up5XhGRUqq0/video.html
      However, if you don't have an updated version of Python or want to print it this way that is perfectly fine too, just use the following code for your print statement :)! It should remove your syntax error!
      print(STORY % (first_adj, name, first_verb, second_adj, first_noun,
      second_noun, animal, food, second_verb, third_noun, fruit,
      third_adj, name, third_verb, number, name, superhero, superhero,
      name, country, name, dessert, name, year, fourth_noun))

    • @StudySessionYT
      @StudySessionYT  Před 3 lety

      Hope my previous comment was able to help you!

    • @hamzahimran3447
      @hamzahimran3447 Před 3 lety +2

      StudySession thank you so much it did!!

  • @girishnaidu5041
    @girishnaidu5041 Před rokem

    Hello I'm a beginner in python..
    I hv a task given by my brother is
    Creat veriable "var1" "var2"
    And assign value 20 and 30
    Perform multiplication operation between var1 and var2 and store the result in "var3"
    Print "var3"
    I'm doing it wrong
    It is showing me syntax error
    Please help me on this

  • @funnynickname1126
    @funnynickname1126 Před 3 lety

    I’m trying to define a font and I can’t fix it. It keeps giving me a syntax error. Can you help?

    • @StudySessionYT
      @StudySessionYT  Před 3 lety

      Could you leave a sample of the code giving you the error here?

    • @funnynickname1126
      @funnynickname1126 Před 3 lety

      @@StudySessionYT I fixed the syntax error but I keep experiencing this one:
      I'm sorry, but an uncaught exception occurred.
      While running game code:
      File "renpy/common/00start.rpy", line 210, in script call
      call _load_reload_game from _call__load_reload_game_1
      File "renpy/common/00keymap.rpy", line 493, in script
      python hide:
      File "renpy/common/00keymap.rpy", line 493, in
      python hide:
      File "renpy/common/00keymap.rpy", line 503, in _execute_python_hide
      renpy.load("_reload-2")
      Exception: Couldn't find a place to stop rolling back. Perhaps the script changed in an incompatible way?

  • @adeyemioluwagbengaprecious8204

    Hi .know matter what I write in my python. I always brings the syntax error stuff.pls get back to me

    • @StudySessionYT
      @StudySessionYT  Před 3 lety

      Could you write here a small bit of code that is giving you a syntax error?

    • @ahmadlakunle9607
      @ahmadlakunle9607 Před 3 lety

      Yes. Something like
      class playercharacter:
      def__innit__(self, name, age):
      Self.name = name
      Self.age = age
      def run(self):
      Print ('run')
      Player1 = playercharacter ('ade' '40')
      Player2 = playercharacter('ola' '40')
      Print (player1.name)
      Print (player2.name)

  • @JacesAviation101
    @JacesAviation101 Před 2 lety

    I’m watching videos on what a variable what a string is and what a syntax error is because I have an exam

  • @ianalexanderamaralbelivuk5693

    Hi, when i put a simple line of code like :
    print(''StudySession'')
    It gives me de message: SyntaxError: invalid syntax. What do i do? obs: I'm using 3.9.1 64-bits

    • @StudySessionYT
      @StudySessionYT  Před 3 lety

      Hmm... that shouldn't give you an error if that is all you're entering. Maybe repeat the steps in my how to install python series and maybe that will fix the problem? I assume maybe there is a problem with the Python interpreter for some reason as that shouldn't be giving you an error!

    • @ianalexanderamaralbelivuk5693
      @ianalexanderamaralbelivuk5693 Před 3 lety +1

      @@StudySessionYT Thank u, but i already fixed the problem, i was just using two quotes instead of just one
      print(''My name is John'') I'M DUMB ASS FUCK SORRY ;-;

    • @StudySessionYT
      @StudySessionYT  Před 3 lety

      @@ianalexanderamaralbelivuk5693 No worries I'm positive I did a lot worst when I first started learning haha, programming can be tough at the beginning but it is super rewarding, best of luck with your learning :)

    • @ianalexanderamaralbelivuk5693
      @ianalexanderamaralbelivuk5693 Před 3 lety +1

      @@StudySessionYT

    • @abineshdhoni9851
      @abineshdhoni9851 Před 2 lety

      Which version of python you use?

  • @ekamssciencefacts2672
    @ekamssciencefacts2672 Před 3 lety

    I sometimes get a syntax error for this. I sometimes it works.......sometimes it doesn't:
    student_grades = [9.1, 8.8, 7.5]
    mysum = sum(student_grades)
    length = len(student_grades)
    mean = mysum / length
    print(mean)