I am trying to create a program that creates a multiplication table of n x n. It's required for the assignment to use repeated addition instead of the multiplication function.
This is the code I have so far:
def main():
import math
print('Hello!')
n = (abs(eval(input("Enter n for the multiplication table n x n: "))))
n = int(n)
a = 0
for i in range(1,n+1):
for x in range(1,n+1):
a = i+a
print(i,' * ',x,' = ',a)
main()
It gives me an output like this:
Hello!
Enter n for the multiplication table n x n: 4
1 * 1 = 1
1 * 2 = 2
1 * 3 = 3
1 * 4 = 4
2 * 1 = 6
2 * 2 = 8
2 * 3 = 10
2 * 4 = 12
3 * 1 = 15
3 * 2 = 18
3 * 3 = 21
3 * 4 = 24
4 * 1 = 28
4 * 2 = 32
4 * 3 = 36
4 * 4 = 40
The output is obviously incorrect, so what can I change/add to fix the calculations?
eval(input(...)). Useint(input()in this case.