Return to Video

05-04 Syntax Vs Semantics Solution

  • 0:00 - 0:03
    [Narrator] 2 + 2, we're actually pretty sure this works out.
  • 0:03 - 0:06
    There's no error for this one; it's going to evaluate to 4.
  • 0:06 - 0:09
    Down here Mars=Earth + 1.
  • 0:09 - 0:14
    There is actually going to be a problem here, and the problem relates to Earth,
  • 0:14 - 0:17
    which is a variable that's used before it's being defined,
  • 0:17 - 0:20
    and python's going to emit some sort of run-time error saying,
  • 0:20 - 0:24
    "I don't know what Earth is so I don't know how to assign Earth + 1 to the variable Mars."
  • 0:24 - 0:27
    This one will result in some sort of error.
  • 0:27 - 0:30
    Over here, we assign Mars to be 4, and that's totally fine, and then we assign
  • 0:30 - 0:33
    Mars to be Mars + 0 or another 4, so no errors here,
  • 0:33 - 0:39
    but, finally, in this last one, we take a string, Mars, and we add an integer, 2, to it,
  • 0:39 - 0:42
    and we don't expect addition to work on both strings and integers.
  • 0:42 - 0:44
    This one also leads to an error.
  • 0:44 - 0:49
    Mars is sometimes called the red planet, the fourth rock from the sun, and among other things,
  • 0:49 - 0:55
    it features very prominently in Gustav Holst's 7 movement orchestral suite, The Planets,
  • 0:55 -
    which was written in about 1915, worth giving a listen to if you haven't yet run into it.
Title:
05-04 Syntax Vs Semantics Solution
Description:

dummy description

more » « less
Video Language:
English
Team:
Udacity
Project:
CS262 - Programming Languages
Duration:
01:00
Amara Bot added a translation

English subtitles

Revisions