-1

My ultimate goal is to make a function that takes a number and returns the prime factorization, which I have achieved. Currently, it returns a list in the form of [number,power] with every prime to every power. What I want to do is take that list and turn it into a bunch of strings that say "the prime factors of this number are: number to power, number to power," etc. Also, unrelated question: how do I get the python error screen to stay. I've resorted to creating a batch file to auto-start the python file so I can take a screenshot of it and read the error, because it instantly goes away.

computergorl
  • 133
  • 1
  • 8

2 Answers2

0

Python provides some pretty nice ways of doing this. For example:

>>> a = [[2,3], [4,5]]
>>> ", ".join("{0} to {1}".format(n, p) for n, p in a)
'2 to 3, 4 to 5'

This is called a generator expression.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
0

If you right click on the python file, click edit with IDLE, and then click f5 to run your program, something like this would appear.

Python 3.5.1 (v3.5.1:37a07cee5969, Dec  6 2015, 01:38:48) [MSC v.1900 32  bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.

This will allow the code to run in a window known a Python Shell, where the error message would stay.

Nikolay Kostov
  • 16,433
  • 23
  • 85
  • 123