This repository was archived by the owner on Nov 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPRIME_FACTORIZATION_TWO.html
More file actions
157 lines (125 loc) · 13.7 KB
/
Copy pathPRIME_FACTORIZATION_TWO.html
File metadata and controls
157 lines (125 loc) · 13.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<hr>
<p><strong>PRIME_FACTORIZATION_TWO</strong></p>
<hr>
<p><span style="background:#ffff00">The <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Python_(programming_language)" target="_blank" rel="noopener">Python</a> program featured in this tutorial web page factorizes some integer, N, into its constituent <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Prime_number" target="_blank" rel="noopener">prime</a> <a style="background:#000000;color:#ff9000" href="https://karlinaobject.wordpress.com/numbers/" target="_blank" rel="noopener">number</a> multiplicative terms (if N is prime number factorizable). Results are printed to the command line terminal interface and to an output text file. Users can input multiple values for N by either choosing to enter another N value or else exiting the program after each value for N is entered.</span></p>
<p><span style="background:#00ffff"><strong><em>Note that the Python program featured on this web page functions identically (except for how it names the program output file and the fact that it does not print the input prompt nor the input value if that value is “out of range”) to the <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/C%2B%2B" target="_blank" rel="noopener">C++</a> program featured in the tutorial web page named <a style="background:#000000;color:#00ff00" href="https://karbytesforlifeblog.wordpress.com/prime_factorization/" target="_blank" rel="noopener">PRIME_FACTORIZATION</a>. Details about how that program language translation was accomplished (using <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/GPT-4o" target="_blank" rel="noopener">ChatGPT-4o</a>) are available in the blogging web page at the following Uniform Resource Locator: <a style="background:#000000;color:#00ff00" href="https://karbytesforlifeblog.wordpress.com/karbytes_23_september_2024/" target="_blank" rel="noopener">https://karbytesforlifeblog.wordpress.com/karbytes_23_september_2024/</a></em></strong></span></p>
<p>A <strong>prime number</strong> is a natural number which is larger than or equal to 2 and which is the multiplicative product of only itself and 1.</p>
<p>A <strong>composite number</strong> is a natural number which is larger than 1 and which is the multiplicative product of two or more prime numbers.</p>
<p><em>To view hidden text inside each of the preformatted text boxes below, scroll horizontally.</em></p>
<hr>
<p><strong>SOFTWARE_APPLICATION_COMPONENTS</strong></p>
<hr>
<p>python_source_file: <a style="background:#000000;color:#00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_extension_pack_20/main/prime_factorization.py" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_extension_pack_20/main/prime_factorization.py</a></p>
<p>plain_text_file: <a style="background:#000000;color:#ff9000" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_extension_pack_20/main/prime_factorization_two_output.txt" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_extension_pack_20/main/prime_factorization_two_output.txt</a></p>
<hr>
<p><strong>PROGRAM_INTERPRETATION_AND_EXECUTION</strong></p>
<hr>
<p>STEP_0: Copy and paste the Python <a style="background:#000000;color:#00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_extension_pack_20/main/prime_factorization.py" target="_blank" rel="noopener">source code</a> into a new text editor document and save that document as the following file name:</p>
<pre>prime_factorization.py</pre>
<p>STEP_1: Open a <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Unix" target="_blank" rel="noopener">Unix</a> command line terminal application and set the current directory to wherever the Python program file is located on the local machine (e.g. Desktop).</p>
<pre>cd Desktop</pre>
<p>STEP_2: Run the program by entering the following command:</p>
<pre>python3 prime_factorization.py</pre>
<p>STEP_3: If the program interpretation command does not work, then use the following commands (in top-down order) to install the Python interpreter:</p>
<pre>sudo apt update</pre>
<pre>sudo apt install python3</pre>
<p>STEP_4: After running the Python program is booted up, the following prompt will appear:</p>
<pre>Enter a nonnegative integer value to store in the variable named N which is no larger than 10000 to factor into its constituent prime number multiplicative terms: </pre>
<p>STEP_5: Enter a value for N using the keyboard.</p>
<p>STEP_6: Observe program results on the command line terminal and in the <a style="background:#000000;color:#ff9000" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_extension_pack_20/main/prime_factorization_two_output.txt" target="_blank" rel="noopener">output file</a>.</p>
<hr>
<p><strong>PROGRAM_SOURCE_CODE</strong></p>
<hr>
<p>Note that the text inside of each of the the preformatted text boxes below appears on this web page (while rendered correctly by the <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Web_browser" target="_blank" rel="noopener">web browser</a>) to be identical to the content of that preformatted text box text’s respective <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Plain_text" target="_blank" rel="noopener">plain-text</a> file or <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Source_code" target="_blank" rel="noopener">source code</a> output file (whose <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/URL" target="_blank" rel="noopener">Uniform Resource Locator</a> is displayed as the <strong style="background:#000000;color:#00ff00">green</strong> <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Hyperlink" target="_blank" rel="noopener">hyperlink</a> immediately above that preformatted text box (if that hyperlink points to a <strong>source code file</strong>) or whose Uniform Resource Locator is displayed as the <strong style="background:#000000;color:#ff9000">orange</strong> hyperlink immediately above that preformatted text box (if that hyperlink points to a <strong>plain-text file</strong>)).</p>
<p><em>Note that, unlike C++ program files (which are <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Compiler" target="_blank" rel="noopener">compiled</a> into machine-executable instructions before program runtime), Python program files are <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Interpreter_(computing)" target="_blank" rel="noopener">interpreted</a> one line at a time instead.</em></p>
<p><em>(Note that angle brackets which resemble <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/HTML" target="_blank" rel="noopener">HTML</a> tags (i.e. an “is less than” symbol (i.e. ‘<‘) followed by an “is greater than” symbol (i.e. ‘>’)) displayed on this web page have been replaced (at the source code level of this web page) with the Unicode symbols <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Less-than_sign" target="_blank" rel="noopener">U+003C</a> (which is rendered by the web browser as ‘<‘) and <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Greater-than_sign" target="_blank" rel="noopener">U+003E</a> (which is rendered by the web browser as ‘>’). That is because the <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/WordPress.com" target="_blank" rel="noopener">WordPress</a> web page editor or web browser interprets a plain-text version of an “is less than” symbol followed by an “is greater than” symbol as being an opening HTML tag (which means that the WordPress web page editor or web browser deletes or fails to display those (plain-text) inequality symbols and the content between those (plain-text) inequality symbols)).</em></p>
<p>python_source_file: <a style="background:#000000;color:#00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_extension_pack_20/main/prime_factorization.py" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_extension_pack_20/main/prime_factorization.py</a></p>
<hr>
<pre>
# /**
# * file: prime_factorization.py
# * type: Python
# * date: 22_SEPTEMBER_2024
# * author: karbytes
# * license: PUBLIC_DOMAIN
# */
import os
# Define the maximum value for N
MAXIMUM_N = 10000
# Function to print the prime factorization of a number N to an output stream (console and file)
def print_prime_factorization(N, output):
if N 1:
while N % divisor == 0:
if not first_factor:
output.write(" * ")
output.write(f"{divisor}")
N //= divisor
first_factor = False
divisor += 1
output.write(".\n")
# Program entry point
def main():
# Initialize N and input_additional_values
N = 0
input_additional_values = 1
# Open the output file for writing
with open("prime_factorization_two_output.txt", "w") as file:
# Print an opening message to the console and the file
print("\n\n--------------------------------")
print("Start Of Program")
print("--------------------------------")
file.write("--------------------------------\n")
file.write("Start Of Program\n")
file.write("--------------------------------\n")
while input_additional_values != 0:
# Prompt the user to enter a value for N
try:
N = int(input(f"\n\nEnter a nonnegative integer value to store in the variable named N which is no larger than {MAXIMUM_N}: "))
if 0 <= N <= MAXIMUM_N:
# Print the prime factorization of N to the file and console
print_prime_factorization(N, file)
print_prime_factorization(N, output=os.sys.stdout)
else:
print(f"Error: N must be between 0 and {MAXIMUM_N}.")
except ValueError:
print("Invalid input. Please enter a valid integer.")
# Ask if the user wants to input another value
input_additional_values = int(input("\n\nWould you like to continue inputting program values? (Enter 1 if YES, Enter 0 if NO): "))
# Print a closing message to the console and the file
print("\n\n--------------------------------")
print("End Of Program")
print("--------------------------------\n\n")
file.write("\n\n--------------------------------\n")
file.write("End Of Program\n")
file.write("--------------------------------\n")
if __name__ == "__main__":
main()
</pre>
<hr>
<p><strong>SAMPLE_PROGRAM_OUTPUT</strong></p>
<hr>
<p>The text in the preformatted text box below was generated by one use case of the Python program featured in this <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Computer_programming" target="_blank" rel="noopener">computer programming</a> tutorial web page.</p>
<p><em>(Note that the aforementioned Python program specifies to name the output file <strong>prime_factorization_two.txt</strong> instead of <strong>prime_factorization.txt</strong> because karbytes did not want the <a style="background:#000000;color:#00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_extension_pack_20/main/prime_factorization.cpp" target="_blank" rel="noopener">C++ program’s</a> output file (which is named <a style="background:#000000;color:#ff9000" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_extension_pack_20/main/prime_factorization_output.txt" target="_blank" rel="noopener">prime_factorization.txt</a>) to be overwritten with the Python program output file in the GitHub repository which houses both output files and which is named <a style="background:#00ff00;color:#000000" href="https://github.com/karlinarayberinger/KARLINA_OBJECT_extension_pack_20/" target="_blank" rel="noopener">KARLINA_OBJECT_extension_pack_20</a>).</em></p>
<p>plain_text_file: <a style="background:#000000;color:#ff9000" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_extension_pack_20/main/prime_factorization_two_output.txt" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_extension_pack_20/main/prime_factorization_two_output.txt</a></p>
<hr>
<pre>
--------------------------------
Start Of Program
--------------------------------
Prime factorization of 10 is: 2 * 5.
Prime factorization of 12 is: 2 * 2 * 3.
Prime factorization of 13 is: 13.
0 is not factorizable into multiple prime number multiplicative terms.
Prime factorization of 100 is: 2 * 2 * 5 * 5.
Prime factorization of 256 is: 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2.
Prime factorization of 201 is: 3 * 67.
1 is not factorizable into multiple prime number multiplicative terms.
Prime factorization of 2 is: 2.
Prime factorization of 999 is: 3 * 3 * 3 * 37.
--------------------------------
End Of Program
--------------------------------
</pre>
<hr>
<p>This web page was last updated on 06_NOVEMBER_2024. The content displayed on this web page is licensed as <a style="background:#000000;color:#ff9000" href="https://karlinaobject.wordpress.com/public_domain/" target="_blank" rel="noopener">PUBLIC_DOMAIN</a> intellectual property.</p>
<hr>