Last active
August 29, 2015 14:08
-
-
Save JanneSalokoski/15405915dcd6e4df7dfd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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