+ 1
Confused about this.
can someone explain to me why print("1.\n2.\n3.\n4.\n5.\n6.\n7.\n8.\n9.") is correct and print ("""1. 2. 3. 4. 5. 6. 7. 8. 9.""") is wrong. The problem was to output the numbers 1 to 9, each on a separate line, followed by a dot. both of the codes do the same thing, but the website accepts the code with /n.
3 Answers
+ 5
Orpheus Lumen ,
when removing all trailing whitespace from the second code sample it will run cuccessfully for code coach.
+ 4
Both of your codes do the same thing, the result is exactly the same. Maybe the website you mention, validates also the code itself. But generally in this situation it would be best to use a loop! Always think about that when you have to code a repeating operation (in this case: print a number).
for x in range(1, 10):
print(str(x) + '.')
+ 2
Python for Beginners, 13 â maybe you have some white space character in the 2nd example?