This script is for a student who has never programmed before. The goal is that she can quickly start to understand what is going on and start to tinker with it.
As I am not very familiar with Python I wonder whether I am breaking any important style paradigm and whether there are things that can make the code further readable, by making it shorter or simpler.
# Define function def npn(n): """ Find the next perfect number after integer n """ org = n = abs(n) while True: n += 1 # Keep track of sum of the positive divisors spd = 1 # Now check (other) possible divisors. # Note that subset of divisors to check can be greatly reduced... # which will increase efficiency for i in range(2, n): # Check divisibility with the modulo operator if (n % i == 0): spd += i if n == spd: print("The next perfect number after", org, "is", n) break # Get user input print("\n", "Check what is the next perfect number after n.") while True: try: x = int(input("Enter your n: ")) except ValueError: print("n should be a postive integer!") continue if x < 8128: break print("Oh. Finding perfect numbers is hard. Choose a lower number. Plz.") # Run function with user input npn(x)