+ 1

Invalid syntax Python code

print("You're born") print("age: 1") friend = input("a kid named Jon whants to be your Friend do you want to be his friend 1- Yes 2-No ") if friend = "1" print("You have now a friend") else: print("You have no friends :( ") Please help im trying to code a lifegame

11th Aug 2023, 1:07 PM
KingLarypto
KingLarypto - avatar
6 ответов
+ 4
Marian , In first statement for accessing quotation mark you have to use backslash (\) before quotation mark.... And in if condition for checking you have to use (==)...it is the correct syntax ... If one equal sign means it indicates... assigning value to the variable.... Try this:- https://code.sololearn.com/cEeH4FraxQva/?ref=app
11th Aug 2023, 1:19 PM
Riya
Riya - avatar
+ 3
Brian yeah you are right bro... thank you so much...since I missed it... Exactly if the whole string is enclosed within single quote means my statement is valid... Since within double quotes so no backslash needed...
11th Aug 2023, 6:26 PM
Riya
Riya - avatar
+ 2
The first error is in line 2. print("age: 1")<74 spaces>friend = input(... All those spaces are unnecessary, and it needs a newline before friend. The second problem, as mentioned by Riya, is using the assignment operator (=) instead of the equality comparison operator (==) in the if conditional. That's a very common mistake that nearly all programmers make - from beginner to pro! (FYI, "wants" is misspelled.) And finally, there is a missing colon (:) from the end of the if statement.
11th Aug 2023, 6:22 PM
Brian
Brian - avatar
+ 2
Riya, the single quote does not need to have a backslash escape. The whole string is delimited by a pair of double quotes, so a single quote may embedded inside without having to escape it. The reverse holds true as well: you can embed a double quote inside a pair of single quotes without having to escape the double quote. That is the reason behind being able to use either type of quote mark for strings.
11th Aug 2023, 6:22 PM
Brian
Brian - avatar
0
Than you
11th Aug 2023, 1:55 PM
KingLarypto
KingLarypto - avatar
0
There is missing colon in if statement
13th Aug 2023, 8:47 AM
AAYUSH AGARWAL
AAYUSH AGARWAL - avatar