Python Forum

Full Version: how to make a program with a certain number of multiples?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
how to make a program if it met with certain multiples of these numbers will produce a different output
example: I have numbers 1 - 20 these numbers will have the same output except 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 plus the string in front to distinguish that they are multiples of 2 besides their multiples of 2 only has regular integer output.
output:
1
2 different
3
4 different
5
6 different
7
8 different
9
10 different
etc

how do you make the program?

I've tried using a for loop and range function with an if statement but it still produces output that doesn't match what I want
Hello, post the code which you used (in [python] code tags). It's quite likely that your code is close to solution you want, just need a little tweaking.
You can also post the output of your current code (in [output] tags).
Try below to see if that helps,

x=int(input("enter max numbers to test: "))
y=int(input("multiple of whihc number to be different: "))
i=1
while (i <= x ):
	if ( i % y == 0 ):
		print("--->", i)
	else:
		print(i)
	i += 1
	
Best Regards,
Sandeep

GANGA SANDEEP KUMAR
(Jan-01-2020, 01:50 PM)sandeep_ganga Wrote: [ -> ]Try below to see if that helps,

x=int(input("enter max numbers to test: "))
y=int(input("multiple of whihc number to be different: "))
i=1
while (i <= x ):
	if ( i % y == 0 ):
		print("--->", i)
	else:
		print(i)
	i += 1
	
Best Regards,
Sandeep

GANGA SANDEEP KUMAR

Thank you for your help :)

(Jan-01-2020, 01:37 PM)j.crater Wrote: [ -> ]Hello, post the code which you used (in [python] code tags). It's quite likely that your code is close to solution you want, just need a little tweaking.
You can also post the output of your current code (in [output] tags).

Alright, thanks for the advice Smile