Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JanneSalokoski/15405915dcd6e4df7dfd to your computer and use it in GitHub Desktop.
Save JanneSalokoski/15405915dcd6e4df7dfd to your computer and use it in GitHub Desktop.
def multiplicationTable(n):
# Is readable and the ouput looks good.
y = 1; result = ""
for i in range(1, n + 1):
x = 1
for j in range(1, n + 1):
result += "{:3}".format(x * y)
x += 1
result = result + "\n"
y += 1
return result
def simpleMultiplicationTable(n):
# Is readable, but the output doesn't look good.
y = 1
for i in range(1, n + 1):
x = 1
for j in range(1, n + 1):
print(x * y, end="\t")
x += 1
print("\n", end="")
y += 1
def complexMultiplicationTable(n):
# Isn't readable, but the output looks good.
for row in range(1, n + 1):
print( * ("{:3}".format(row * col) for col in range(1, n + 1)))
i = int(input("Anna luku, jonka kertotaulu tulostetaan: "))
print(multiplicationTable(i))
#simpleMultiplicationTable(i)
#complexMultiplicationTable(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment