136k views
0 votes
7. Write a python program to get the following output.

1-----99
2-----98
3-----97
. .
. .
. .
98-----2
99-----1
whats is the code of this question

1 Answer

6 votes

Answer:

for i in range(1,100):

print(f"{i}-----{100 - i}")

OR:

for i in range(1,100):

print(str(i)+"-----"+str(100 - i)")

Step-by-step explanation:

First off, we can see that the program starts off with an iteration of 1 and ends at 100. So we use this loop code to begin:

for i in range(1,100):

Then, we use this code to print the pattern (make sure to indent this):

print(str(i)+"-----"+str(100 - i)")

We can also use f-strings as a better and cleaner alternative (make sure to indent this too):

print(f"{i}-----{100 - i}")

This code will get us the output shown in the question.

User Karlosos
by
7.6k points

No related questions found

Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.