Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pattern question
#1
'''
5 4 3 2 1
5 4 3 2 1
5 4 3 2 1
5 4 3 2 1
5 4 3 2 1
'''
'''I am trying to print the pattern'''
n = int(input("Please enter the number of times "))
for i in range(n):
    for j in range(n, 0 -1):
        print(j, end = " ")
    print()
Output:
Please enter the number of times 3 Process finished with exit code 0
I am not looking for solution but please tell me why is that, it is not printing the output. In regards to solution, I am still working on it.

I made a big time small mistake, Thank you
Reply
#2
for j in range(n, 0 -1):
A comma is missing:
for j in range(n, 0, -1):
range accepts one, two or three arguments.

This code: range(n, 0 -1)
Is evaluated to: range(n, -1)
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  pattern question spalisetty06 2 2,227 Jul-24-2020, 10:28 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020