Python Forum
Explain this code - for loop
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Explain this code - for loop
#2
in your first snippet you need to indent the print 2 levels - to be indented one level compared to inner loop.

for i in range(1, 11):
    for j in range(n):
        print (i * j)
few observations:
  • you may want to change the second for loop to start from 1 and include n. Currently it will start from 0 and will not include n
  • you may want to change the print function to display also bot multiples not just the result.

in the second snippet the syntax with d% that you ask about is called string formatting. that is so called old-styled string formatting. there is newer str.format() method and from 3.6+ - also f-strings
Here is the docs for string format syntax
Here is comparison between old-style and str.format() method: https://pyformat.info/
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
Explain this code - for loop - by RavCOder - Sep-24-2019, 12:13 PM
RE: Explain this code - for loop - by buran - Sep-24-2019, 12:25 PM
RE: Explain this code - for loop - by ichabod801 - Sep-24-2019, 12:28 PM
RE: Explain this code - for loop - by buran - Sep-24-2019, 12:31 PM
RE: Explain this code - for loop - by ichabod801 - Sep-24-2019, 12:36 PM
RE: Explain this code - for loop - by RavCOder - Sep-24-2019, 12:42 PM
RE: Explain this code - for loop - by buran - Sep-24-2019, 12:45 PM
RE: Explain this code - for loop - by RavCOder - Sep-24-2019, 12:47 PM
RE: Explain this code - for loop - by buran - Sep-24-2019, 12:56 PM
RE: Explain this code - for loop - by RavCOder - Sep-24-2019, 01:01 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [split] Explain the python code in this definition Led_Zeppelin 1 773 Jan-13-2023, 10:20 PM
Last Post: deanhystad
  I am new to python and Could someone please explain how this below code is working? kartheekdas 2 1,054 Dec-19-2022, 05:24 PM
Last Post: kartheekdas
  Explain the python code in this definition Led_Zeppelin 1 1,132 Oct-27-2022, 04:04 AM
Last Post: deanhystad
  Sudoku Solver in Python - Can someone explain this code ? qwemx 6 2,189 Jun-27-2022, 12:46 PM
Last Post: deanhystad
  Can someone explain this small snippet of code like I am a 5 year old? PythonNPC 3 1,293 Apr-08-2022, 05:54 PM
Last Post: deanhystad
  Could you explain each part of the code? Tsushida 2 1,554 Mar-20-2022, 08:19 AM
Last Post: Larz60+
  What is the run time complexity of this code and please explain? samlee916 2 2,330 Nov-06-2020, 02:37 PM
Last Post: deanhystad
  poplib - parsing message body, could somebody please help explain this code t4keheart 2 2,339 Oct-12-2020, 01:59 PM
Last Post: t4keheart
  Explain range in this code RavCOder 4 2,399 Oct-02-2019, 05:04 PM
Last Post: jefsummers
  Need explain about the code ap111 2 1,970 Sep-12-2019, 03:10 PM
Last Post: luoheng

Forum Jump:

User Panel Messages

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