python - SyntaxError: EOL while scanning string literal: TOTEM -
this question has answer here:
we have create totem pole using strings consisting of 13 characters wide. each head must have different characteristics. of functions characteristics below. however, when ran code gave me syntax error above.
import random def hair_spiky(): return"/\/\/\/\/\/\/" def hair_middlepart(): return"\\\\\\ //////" def eye_crossed(): a1= r" ____ ____" a2= r"/ \ / \" a3= r"| o| |o |" a4= r"\____/ \____/" return a1 +"\n" + a2 + "\n" + a3 + "\n" a4 def eye_left(): a1=r" ____ ____" a2=r"/ \ / \" a3=r"|o | |o |" a4=r"\____/ \____/"
you cannot use \
last character in raw string literal:
r"\"
not valid string literal (even raw string cannot end in odd number of backslashes). specifically, a raw string cannot end in single backslash (since backslash escape following quote character).
don't use raw string there; double backslashes instead:
a2= "/ \\ / \\"
or use raw multiline string using triple quotes:
def eye_crossed(): return r""" ____ ____ / \ / \ | o| |o | \____/ \____/"""[1:] def eye_left(): return r""" ____ ____ / \ / \ |o | |o | \____/ \____/"""[1:]
the slice used remove initial newline part of string.
Comments
Post a Comment