Computer Science, asked by mrgoodb62, 1 month ago

Rewrite the following co,de in Python after removing all syntax errors(s). Underline each correction done in the co,de.
for Name in [Amar, Shveta, Parag]
if Name [0] = ‘s’:
Print (Name)​

Answers

Answered by Equestriadash
9

Given co‎de:

\tt for\ N ame\ in\ [Amar,\ Shveta,\ Parag]\\if\ N ame[0]\ =\ "s":\\Print\ (N ame)

Corrected co‎de:

\tt for\ N ame\ in\ ["Amar",\ "Shveta",\ "Parag"]:\ \longrightarrow\ \sf Correction\ 1\ \&\ 2\\{\ \ \ \ \ }if\ N ame[0]\ ==\ "s":\ \longrightarrow\ \sf Correction\ 3\\{\ \ \ \ \ }{\ \ \ \ \ }print\ (N ame)\ \longrightarrow\ \sf Correction\ 4

Explanation:

Correction 1 & 2:

  • Any text value must be enclosed in quotes to be represented as strings. In the given c‎ode, the names Amar, Shveta and Parag were not enclosed in quotes. The c‎ode would result in an error as Amar, Shveta and Parag are assumed to be variables instead of values.
  • The syntax of a \tt for statement includes a colon at the end to indicate the next c‎ode block.

Correction 3:

  • The equal to (=) and double-equal to (==) symbols are both different in Python. A single equal to symbol (=) represents an assignment, i.e., a value being assigned to a variable. A double-equal to symbol (==) represents a test for equality, i.e., the interpreter will check if the LHS and the RHS are equivalent.

Correction 4:

  • The syntax of a \tt print statement is 'print' in smaller case. Since Python is a case-sensitive language, 'P' and 'p' are not the same.

Equestriadash: Thanks for the Brainliest! ^_^"
Similar questions