not giving output the way I’m expecting

Parv Naithani

Print the following pattern. There is exactly one space between any two consecutive numbers on any line. There are no spaces at the end of any line.

1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1

this was the question

for i in range(1, 6):
# Print numbers in increasing order
    for j in range(1, i + 1):
        print(j, end=' ')

# Print numbers in decreasing order
    for j in range(i - 1, 0, -1):
        print(j, end=' ')

# Move to the next line
    print()

when we print the above code I’m getting

1 
1 2 1 
1 2 3 2 1 
1 2 3 4 3 2 1 
1 2 3 4 5 4 3 2 1 
Omnia Osman

the correct code should be:

for i in range(2, 6):
    for j in range(1,  i + 1):
        print(j, end=' ')
    for j in range(i - 1, 0, -1):
        print(j, end=' ')
    print()

The first loop will be 4 times, every time should begin with 1, so the range of the second loop starts with 1.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why does Rccp return a list-like output when I was expecting a dataframe output in R?

container.ListBlobs is giving a list of CloudBlobDirectory I was expecting a list of CloudBlockBlobs?

Bootstrap login button not the color I'm expecting

Calling method in superclass not giving the output I expect?

Hive SQL is giving extraneous input ',' expecting ')' error

getXmlEncoding() is giving the wrong output

explode() is giving me blank values I am not expecting

I need to replace Subjects ex :- Subjects :***** but it is giving the output :- Subjects :*****Computer

CML code not giving output

I don't understand why it is giving this output?

program giving different output than what i expected

Redirect not working as I'm expecting in Rails

AES function giving not the output that I expected

Class MinStack not giving output

Node module giving no output - have I misunderstood how to install it?

in search giving false when expecting true

Valid JSON giving JSONDecodeError: Expecting , delimiter (2)

My PHP sessions giving me wrong output when I login

I'm confused with a output . So I'm expecting explaination For my output

C program is not giving out the required output from the "correct" input I'm giving it

getting no output (expecting boolean output)

I am a beginner and using pascal. I don't know how to code the output. I am expecting the output to be the result of the function

I have written a function but it isnt giving the output i expected

This is a Roman numeral to integer program, but the output is not what i was expecting

Output of split is not what I was expecting

I am expecting output as int, but getting float

Could someone explain me the output of "str("Hello") == str("World!")" in R. I was expecting "TRUE"

What's the proper way to execute some logic in reactor if I'm expecting empty values?

Why is the following output giving the response instead of what I am expecting?