+ 3
Can someone give me a code of python in this question 🙏🏼
Write a program that displays multiple of 3 from 300 to 100
11 Answers
+ 5
First try then if there is problem on the code ask
+ 3
n=0
for n in range(300,100,-1):
if n%3==0:
print(n)
n=n+3
Yes this is working it gives the answer...indent below the print to get answer
+ 1
Post your attempt first
+ 1
Disha Jain i edited your code a little . added -1 as 3rd parameter to range and did proper indent to n+=3 line .
n=0
for n in range(300,100,-1):
if n%3==0:
print(n)
n=n+3
+ 1
I think this is more correct...
for n in range(300, 100 - 1, -1):
if n % 3 == 0:
print(n)
0
n=0
for n in range(300,100):
if n%3==0:
print(n)
n=n+3
I tried this...but this give me no output
0
Md Sayed thankuu so much
0
Hi😊
try adding steps in the range function☺.
adding negative step will reserve movement, else you will find no output.
range(300, 100, -1)
if you want to learn more look at this ----->
"The Python range() Function (Guide) – Real Python"
https://realpython.com/python-range/
0
print(*[n for n in range(300,100,-1) if n%3==0])
Or since the start of 300 is divisible by 3 you can step by -3:
print(*range(300,100,-3))
0
Disha Jain Here's the solution as a one-liner:
for x in range(300, 100, -3): print(x)
Or
print(*range(300, 100, -3), sep='\n')
# Hope this helps
0
Just use the step value.
for i in range (300,100,-3) :
print (i)
That's it .👍