Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Escape indentation
#6
Frankduc Wrote:Wonder what is the principle idea behind the scene to be force to create a new variable to escape the indent.
Your design is wrong from the start because the role of function is_prime_v1() is not well defined. It tells whether n is prime by returning a boolean, and at the same time, it appends items to the prime list and returns the value of n. These are too many tasks for a single function.
def is_prime_v1(n):
    """Return a boolean indicating if integer n is prime"""
    if n == 1:
     return False
     
    for d in range(2, n):
        if n % d == 0:
            return False
    return True

prime = []
for n in range(1,21):
  if is_prime_v1(n):
    prime.append(n)

print(prime)
Output:
[2, 3, 5, 7, 11, 13, 17, 19]
BashBedlam and Frankduc like this post
Reply


Messages In This Thread
Escape indentation - by Frankduc - Jan-28-2022, 02:25 PM
RE: Escape indentation - by BashBedlam - Jan-28-2022, 02:53 PM
RE: Escape indentation - by Frankduc - Jan-28-2022, 03:05 PM
RE: Escape indentation - by snippsat - Jan-28-2022, 03:13 PM
RE: Escape indentation - by Frankduc - Jan-28-2022, 03:36 PM
RE: Escape indentation - by Gribouillis - Jan-28-2022, 03:41 PM
RE: Escape indentation - by Frankduc - Jan-28-2022, 04:07 PM
RE: Escape indentation - by deanhystad - Jan-28-2022, 04:24 PM
RE: Escape indentation - by Frankduc - Jan-28-2022, 04:50 PM
RE: Escape indentation - by deanhystad - Jan-28-2022, 07:24 PM
RE: Escape indentation - by Gribouillis - Jan-28-2022, 09:59 PM
RE: Escape indentation - by Frankduc - Jan-31-2022, 02:41 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  use of escape character in re.sub and find WJSwan 1 984 Feb-16-2023, 05:19 PM
Last Post: Larz60+
  add Escape charcters in string GrahamL 3 1,271 Jan-20-2022, 01:15 PM
Last Post: GrahamL
  Escape Single quotation between each content tag usman 3 2,950 May-02-2021, 03:32 PM
Last Post: snippsat
  DIY Escape Room for fun StannemanPython 1 2,430 Feb-17-2021, 10:53 PM
Last Post: maurom82
  How to escape OrderedDict as an argument? Mark17 2 2,116 Dec-23-2020, 06:47 PM
Last Post: Mark17
  help for escape sequences NewPi 1 2,112 Dec-11-2019, 11:22 PM
Last Post: ichabod801
  escape single quote deep_logic 1 1,869 Sep-10-2019, 08:05 PM
Last Post: SheeppOSU
  The use of escape char \ hishamzero1 2 2,450 Aug-12-2019, 10:20 PM
Last Post: hishamzero1
  Escape sequences display in python Uchikago 1 2,522 Jun-27-2019, 03:25 PM
Last Post: Gribouillis
  Python 3 escape codes oldDog 1 2,664 Sep-15-2018, 10:12 AM
Last Post: gruntfutuk

Forum Jump:

User Panel Messages

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