Program That Reads 2 Positive Integer And Print The First Multiples Of It Only Using "while"
I'm trying to write a program that reads 2 positive integers (m and n), and then print the n first positive integers of m using only while loop.
Here is the original question
Write a program in the Python 3.x language that reads two positive integers, m and n, and print the first n positive integers that are multiples of m.
And the output of the code should look like:
Type a positive integer for m: 9 Type a positive integer for n: 5 The first 5 positive integers multiples of 9 are: 9 18 27 36 45
So I have done so far:
m = int(input("Type a integer for m: ")) n = int(input("Type a integer for n: ")) i = 1 print() print("The first ",n,"positive integers multiples of ", m," are:") while i <= n: m = m * i print(m) i = i + 1
I wanna understand how to fix this one and I realize that using for or if it's gonna be easier to do that
Nullman's asnwer is the right one, anyways here is your code corrected, just in case it may help you understand better the error:
m = 9 n = 5 i = 1 print() print("The first ",n,"positive integers multiples of ", m," are:") while i <= n: multiple = m * i print(multiple) i = i + 1
You cannot use
if, but you could indeed use
m = 9 n = 5 i = 1 print() print("The first ",n,"positive integers multiples of ", m," are:") for i in range(1, n + 1): multiple = m * i print(multiple) i = i + 1
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module