0

How to do the next problem just using while an maybe the conditional if?

A program that show the first 10 multiples of 3. Im learning how to use the counters. And I dont know how to begin to solve it. And example could be this problem to print pair numbers. end = int(input("Put the last number to print:")) x = 0 while x<= end: print(x) x = x + 2

20th Aug 2018, 6:27 PM
Rody Oswaldo Mendez Villarreal
Rody Oswaldo Mendez Villarreal - avatar
9 ответов
+ 2
Rody Oswaldo Mendez Villarreal see this example, I'm also still learning, but I guess this is how it works : ) counter, num = 0, 0 # repeat while counter is less than or equal to 10 while counter <= 10: # print num, but don't insert new line # we want next num delimited with space print(num, end = " ") num += 3 # increase num by 3 counter += 1 # increase counter by 1
20th Aug 2018, 7:04 PM
Ipang
+ 2
Your ‘x = x + 2’ line in your example needs to be indented too. Why don’t you try doing that and run it and see what happens?
20th Aug 2018, 7:04 PM
Russ
Russ - avatar
+ 1
thanks all of you for your help, I imagine this problem like to make a multiplication table of 3 right? but using while.
20th Aug 2018, 7:40 PM
Rody Oswaldo Mendez Villarreal
Rody Oswaldo Mendez Villarreal - avatar
+ 1
Rody Oswaldo Mendez Villarreal yes, but I guess the zero didn't feel like it belongs there : )
20th Aug 2018, 8:15 PM
Ipang
+ 1
Rody Oswaldo Mendez Villarreal you forgot to increment 'x' with value of 'multiple' at the bottom. multiple = int(input("Give the number of multiple: ")) print(multiple) end = int (input("Number of multiples you need: ")) print(end) x = 0 y = 0 # changed y to zero to get a range from 0 to (multiple * end) while y <= end: if x % multiple == 0: print(x) y += 1 x += multiple
25th Aug 2018, 7:43 PM
Ipang
+ 1
Thanks a lot Ipang it works as I expected. I will change the range to zero.
25th Aug 2018, 8:03 PM
Rody Oswaldo Mendez Villarreal
Rody Oswaldo Mendez Villarreal - avatar
0
And example of multiples of 3 are 0,3,6,9,12,15,18,21,24,27, and 30. That 10 numbers must be show in the program.
20th Aug 2018, 6:31 PM
Rody Oswaldo Mendez Villarreal
Rody Oswaldo Mendez Villarreal - avatar
0
20th Aug 2018, 6:43 PM
Rody Oswaldo Mendez Villarreal
Rody Oswaldo Mendez Villarreal - avatar
0
I almost have the problem done I have problems to insert the operation to do the multiple the program must ask about the number of the multiple you want and the number of the multiple you want to get. This is the code I've done. multiple = int(input("Give the number of multiple: ")) end = int (input("Number of multiples you need: ")) x = 0 y = 1 while y <= end: if x % multiple == 0: print(x) y += 1
25th Aug 2018, 6:47 PM
Rody Oswaldo Mendez Villarreal
Rody Oswaldo Mendez Villarreal - avatar