in the lesson about lists on learnpython.org there is an exercise. the goal was to create a string that would mach the condisions below.
the conditions are:
Length should be 20
print("Length of s = %d" % len(s))
First occurrence of "a" should be at index 8
print("The first occurrence of the letter a = %d" % s.index("a"))
Number of a's should be 2
print("a occurs %d times" % s.count("a"))
Check how a string starts
if s.startswith("Str"):
print("String starts with 'Str'. Good!")
Check how a string ends
if s.endswith("ome!"):
print("String ends with 'ome!'. Good!")
the answer that is preset is:
s = "Strings are awesome!"
my answer is:
s = "Str thera! whatlome!"
which is also correct. the "correct" answer is so secific that i don't think you could do this exercise without "show solution"
in the lesson about lists on learnpython.org there is an exercise. the goal was to create a string that would mach the condisions below.
the conditions are:
Length should be 20
print("Length of s = %d" % len(s))
First occurrence of "a" should be at index 8
print("The first occurrence of the letter a = %d" % s.index("a"))
Number of a's should be 2
print("a occurs %d times" % s.count("a"))
Check how a string starts
if s.startswith("Str"):
print("String starts with 'Str'. Good!")
Check how a string ends
if s.endswith("ome!"):
print("String ends with 'ome!'. Good!")
the answer that is preset is:
s = "Strings are awesome!"
my answer is:
s = "Str thera! whatlome!"
which is also correct. the "correct" answer is so secific that i don't think you could do this exercise without "show solution"