Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
question about loops
#2
You're almost there. What you've failed to do (because you're new to Python, for which you don't need to be sorry) is to pass an argument to your function.

def Q9(n): # n is an arbitrary variable name
    for i in range(n):
        print(i)

Q9(5)
That will produce an output of:

Output:
0 1 2 3 4
Now, it is possible to produce:

Output:
0 1 2 3 4
... with a simple alteration to the print() function. It's your task to look into what options you can use with said function and post back your solution.

Hint: >>> help(print)
Yoriz and rpang like this post
Sig:
>>> import this

The UNIX philosophy: "Do one thing, and do it well."

"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse

"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
Reply


Messages In This Thread
question about loops - by rpang - Nov-05-2022, 07:19 AM
RE: question about loops - by rob101 - Nov-05-2022, 07:58 AM
RE: question about loops - by rpang - Nov-05-2022, 08:03 AM
RE: question about loops - by rpang - Nov-05-2022, 08:25 AM
RE: question about loops - by rob101 - Nov-05-2022, 08:31 AM
RE: question about loops - by rpang - Nov-05-2022, 11:11 PM
RE: question about loops - by rob101 - Nov-05-2022, 11:47 PM
RE: question about loops - by deanhystad - Nov-07-2022, 09:42 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Homework help:While Loops question Midhat_School 6 3,285 Jul-26-2020, 10:23 AM
Last Post: pyzyx3qwerty

Forum Jump:

User Panel Messages

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