Objective
Develop a Python program that prompts the user for two integer numbers and displays their product without using the "*" operator. It should use consecutive additions. (Hint: remember that 3 * 5 = 3 + 3 + 3 + 3 + 3 = 15)
Example Python Exercise
Show Python Code
# Prompt the user to enter the first number
num1 = int(input("Enter the first number: "))
# Prompt the user to enter the second number
num2 = int(input("Enter the second number: "))
# Initialize the product variable
product = 0
# Use a while loop to calculate the product using consecutive additions
i = 0
while i < num2:
product += num1
i += 1
# Display the product
print(f"The product of {num1} and {num2} is {product}")
Output
Enter the first number: 3
Enter the second number: 5
The product of 3 and 5 is 15
Share this Python Exercise
Explore our set of Python Programming Exercises! Specifically designed for beginners, these exercises will help you develop a solid understanding of the basics of Python. From variables and data types to control structures and simple functions, each exercise is crafted to challenge you incrementally as you build confidence in coding in Python.
This Python program calculates and displays the absolute value of a number x. The absolute value of a number is defined as the number itself if it is positive,...
This Python program prompts the user for a symbol, width, and height, and then displays a hollow rectangle using that symbol for the outer border...
This Python program calculates various basic statistical operations such as sum, average, minimum, and maximum based on user input. The pr...
This Python program prompts the user to input two numbers and then uses the conditional operator (?) to perform a series of checks on the input. The program first che...
This Python program prompts the user to input an integer and determines whether it is a prime number or not. A prime number is defined as a number great...
This Python program calculates the change for a purchase, using the largest possible coins or bills. The program prompts the user for the price o...