148k views
3 votes
Get two positive integers from the user. Write code to multiply the two numbers together using only addition or subtraction. You should not use the '*' operator. Remember that x*y is simply x+x+x+...+x, y times. You may use eitnher a for loop or a while loop

User Rorist
by
9.5k points

1 Answer

2 votes

Answer:

number1 = int(input("Enter the first number: "))

number2 = int(input("Enter the second number: "))

result = 0

for i in range(number1):

result += number2

print(str(result))

Step-by-step explanation:

Ask the user for two numbers

Initialize result as 0 to hold the multiplication of the numbers

Create a for loop that iterates "number1" times. In each iteration, add number2 to the result.

When the loop is done, print the result

User David Villamizar
by
8.4k points

No related questions found