<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://teaching.healthtech.dtu.dk:443/22101/index.php?action=history&amp;feed=atom&amp;title=Simple_File_Reading</id>
	<title>Simple File Reading - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://teaching.healthtech.dtu.dk:443/22101/index.php?action=history&amp;feed=atom&amp;title=Simple_File_Reading"/>
	<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22101/index.php?title=Simple_File_Reading&amp;action=history"/>
	<updated>2026-04-15T08:56:34Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22101/index.php?title=Simple_File_Reading&amp;diff=75&amp;oldid=prev</id>
		<title>WikiSysop: /* Exercises to be handed in */</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22101/index.php?title=Simple_File_Reading&amp;diff=75&amp;oldid=prev"/>
		<updated>2024-10-30T09:05:36Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Exercises to be handed in&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 11:05, 30 October 2024&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l23&quot;&gt;Line 23:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 23:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Exercises to be handed in ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Exercises to be handed in ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Write a program that reads the file &#039;&#039;ex1.acc&#039;&#039; and displays it on the screen. Display it &#039;&#039;&#039;correctly&#039;&#039;&#039; as it is, i.e. the OUTPUT of your print should look precisely like the original file. Hint: look at the lines.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Write a program that reads the file &#039;&#039;ex1.acc&#039;&#039; and displays it on the screen. Display it &#039;&#039;&#039;correctly&#039;&#039;&#039; as it is, i.e. the OUTPUT of your print should look precisely like the original file. Hint: look at the &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;spacing between &lt;/ins&gt;lines.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Make the program ask for a filename (the input file in the following exercises), and display the file on the screen.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Make the program ask for a filename (the input file in the following exercises), and display the file on the screen.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Construct a program that counts the number of lines in the input file, and displays the result. Try it with the file &amp;#039;&amp;#039;ex1.dat&amp;#039;&amp;#039;. There are 1675 lines.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Construct a program that counts the number of lines in the input file, and displays the result. Try it with the file &amp;#039;&amp;#039;ex1.dat&amp;#039;&amp;#039;. There are 1675 lines.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l29&quot;&gt;Line 29:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 29:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Based on the previous program, now make a new one that calculates the mean value of the columns. Create your own test file with some numbers (where you know what the result should be) and feed that to the program.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Based on the previous program, now make a new one that calculates the mean value of the columns. Create your own test file with some numbers (where you know what the result should be) and feed that to the program.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Now make a program that counts the number of positive and negative numbers in an input file. Also count the zeroes in the column, if there are any. Display the result.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Now make a program that counts the number of positive and negative numbers in an input file. Also count the zeroes in the column, if there are any. Display the result.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Now make a program that finds the maximum number in a column. Display the result. This is quite tricky. Hint: &#039;&#039;&#039;None&#039;&#039;&#039; could be useful.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Now make a program that finds the maximum number in a column. Display the result. This is quite tricky. Hint: &#039;&#039;&#039;None&#039;&#039;&#039; could be useful&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;. The max in &#039;&#039;ex1_1.dat&#039;&#039; is 10.4155&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Now make a program that finds the minimum number in a column and display the result.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Now make a program that finds the minimum number in a column and display the result&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;. The max in &#039;&#039;ex1_3.dat&#039;&#039; is -4.3967. Hint: What happens if all the numbers in the file are positive&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# It begins to get trivial. Now make a program that does all of the above, that is; calculate the sum, the number of lines, the mean value, the number of positive, negative and zero numbers, the maximum and the minimum value. You can only read the file once. Display the all results clearly so there is no doubt about what you display.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# It begins to get trivial. Now make a program that does all of the above, that is; calculate the sum, the number of lines, the mean value, the number of positive, negative and zero numbers, the maximum and the minimum value. You can only read the file once. Display the all results clearly so there is no doubt about what you display.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22101/index.php?title=Simple_File_Reading&amp;diff=59&amp;oldid=prev</id>
		<title>WikiSysop: /* Exercises to be handed in */</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22101/index.php?title=Simple_File_Reading&amp;diff=59&amp;oldid=prev"/>
		<updated>2024-09-17T08:18:11Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Exercises to be handed in&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 10:18, 17 September 2024&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l26&quot;&gt;Line 26:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 26:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Make the program ask for a filename (the input file in the following exercises), and display the file on the screen.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Make the program ask for a filename (the input file in the following exercises), and display the file on the screen.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Construct a program that counts the number of lines in the input file, and displays the result. Try it with the file &amp;#039;&amp;#039;ex1.dat&amp;#039;&amp;#039;. There are 1675 lines.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Construct a program that counts the number of lines in the input file, and displays the result. Try it with the file &amp;#039;&amp;#039;ex1.dat&amp;#039;&amp;#039;. There are 1675 lines.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Now make a Python program that sums numbers from &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;a &lt;/del&gt;input file and displays the sum of the numbers. I have created 3 files with the columns from &#039;&#039;ex1.dat&#039;&#039;; &#039;&#039;ex1_1.dat&#039;&#039;, &#039;&#039;ex1_2.dat&#039;&#039; &amp;amp; &#039;&#039;ex1_3.dat&#039;&#039;. Use the 3 files as input and see the sums. The sums are approx. Col 1; -904.4143, Col 2; 482.8410, Col 3; 292.05150 for the three columns.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Now make a Python program that sums numbers from &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;ONE &lt;/ins&gt;input file and displays the sum of the numbers. I have created 3 &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;input &lt;/ins&gt;files with the columns from &#039;&#039;ex1.dat&#039;&#039;; &#039;&#039;ex1_1.dat&#039;&#039;, &#039;&#039;ex1_2.dat&#039;&#039; &amp;amp; &#039;&#039;ex1_3.dat&#039;&#039;. Use the 3 files as input &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;ONE AT A TIME &lt;/ins&gt;and see the sums. The sums are approx. Col 1; -904.4143, Col 2; 482.8410, Col 3; 292.05150 for the three columns.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Based on the previous program, now make a new one that calculates the mean value of the columns. Create your own test file with some numbers (where you know what the result should be) and feed that to the program.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Based on the previous program, now make a new one that calculates the mean value of the columns. Create your own test file with some numbers (where you know what the result should be) and feed that to the program.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Now make a program that counts the number of positive and negative numbers in an input file. Also count the zeroes in the column, if there are any. Display the result.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Now make a program that counts the number of positive and negative numbers in an input file. Also count the zeroes in the column, if there are any. Display the result.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22101/index.php?title=Simple_File_Reading&amp;diff=58&amp;oldid=prev</id>
		<title>WikiSysop: /* Exercises to be handed in */</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22101/index.php?title=Simple_File_Reading&amp;diff=58&amp;oldid=prev"/>
		<updated>2024-09-17T07:52:17Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Exercises to be handed in&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 09:52, 17 September 2024&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l23&quot;&gt;Line 23:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 23:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Exercises to be handed in ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Exercises to be handed in ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Write a program that reads the file &#039;&#039;ex1.acc&#039;&#039; and displays it on the screen. Display it &#039;&#039;&#039;correctly&#039;&#039;&#039; as it is.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Write a program that reads the file &#039;&#039;ex1.acc&#039;&#039; and displays it on the screen. Display it &#039;&#039;&#039;correctly&#039;&#039;&#039; as it is&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;, i.e. the OUTPUT of your print should look precisely like the original file. Hint: look at the lines&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Make the program ask for a filename (the input file in the following exercises), and display the file on the screen.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Make the program ask for a filename (the input file in the following exercises), and display the file on the screen.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Construct a program that counts the number of lines in the input file, and displays the result. Try it with the file &amp;#039;&amp;#039;ex1.dat&amp;#039;&amp;#039;. There are 1675 lines.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Construct a program that counts the number of lines in the input file, and displays the result. Try it with the file &amp;#039;&amp;#039;ex1.dat&amp;#039;&amp;#039;. There are 1675 lines.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22101/index.php?title=Simple_File_Reading&amp;diff=14&amp;oldid=prev</id>
		<title>WikiSysop: Created page with &quot;__NOTOC__ {| width=500  style=&quot;float:right; margin-left: 10px; margin-top: -56px;&quot; |Previous: Python Basics |Next: Pseudocode and Comments |} == Required course material for the lesson == Powerpoint: [https://teaching.healthtech.dtu.dk/material/22101/22101_04-FileReading.ppt Simple File Reading]&lt;br&gt; Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=e51d5f37-84e5-46d4-8252-af270129a697 Simple file reading]&lt;br&gt; Video: [https://panopto.dtu.dk/Panopto/Pages...&quot;</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22101/index.php?title=Simple_File_Reading&amp;diff=14&amp;oldid=prev"/>
		<updated>2024-03-01T15:32:40Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;__NOTOC__ {| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot; |Previous: &lt;a href=&quot;/22101/index.php/Python_Basics&quot; title=&quot;Python Basics&quot;&gt;Python Basics&lt;/a&gt; |Next: &lt;a href=&quot;/22101/index.php/Pseudocode_and_Comments&quot; title=&quot;Pseudocode and Comments&quot;&gt;Pseudocode and Comments&lt;/a&gt; |} == Required course material for the lesson == Powerpoint: [https://teaching.healthtech.dtu.dk/material/22101/22101_04-FileReading.ppt Simple File Reading]&amp;lt;br&amp;gt; Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=e51d5f37-84e5-46d4-8252-af270129a697 Simple file reading]&amp;lt;br&amp;gt; Video: [https://panopto.dtu.dk/Panopto/Pages...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;__NOTOC__&lt;br /&gt;
{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[Python Basics]]&lt;br /&gt;
|Next: [[Pseudocode and Comments]]&lt;br /&gt;
|}&lt;br /&gt;
== Required course material for the lesson ==&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22101/22101_04-FileReading.ppt Simple File Reading]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=e51d5f37-84e5-46d4-8252-af270129a697 Simple file reading]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=def721bf-4e23-407c-9a5b-af2701298919 Objects, the concept. Some examples]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=18b01d1b-91b8-4e22-9303-af27012967ce Loop control, pass statement]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=07d50a0f-d574-444a-9cc9-af27012947c8 Boolean Logic, short-circuit evaluation ]&amp;lt;br&amp;gt;&lt;br /&gt;
Resource: [[Example code - File Reading]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Subjects covered ==&lt;br /&gt;
&amp;#039;&amp;#039;with&amp;#039;&amp;#039; statement, just a simple use of it.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;open&amp;#039;&amp;#039; function for opening files for access. Filehandles.&amp;lt;br&amp;gt;&lt;br /&gt;
Built-in values; &amp;#039;&amp;#039;True&amp;#039;&amp;#039;, &amp;#039;&amp;#039;False&amp;#039;&amp;#039; and &amp;#039;&amp;#039;None&amp;#039;&amp;#039;.&amp;lt;br&amp;gt;&lt;br /&gt;
Loop control with &amp;#039;&amp;#039;continue&amp;#039;&amp;#039; and &amp;#039;&amp;#039;break&amp;#039;&amp;#039; and how NOT to use them.&lt;br /&gt;
&lt;br /&gt;
== Advice ==&lt;br /&gt;
You might want to consider what would happen if you feed an empty file to your program.&amp;lt;br&amp;gt;&lt;br /&gt;
Are you looking for files? See the top line of the [[Programme]] page.&lt;br /&gt;
&lt;br /&gt;
== Exercises to be handed in ==&lt;br /&gt;
# Write a program that reads the file &amp;#039;&amp;#039;ex1.acc&amp;#039;&amp;#039; and displays it on the screen. Display it &amp;#039;&amp;#039;&amp;#039;correctly&amp;#039;&amp;#039;&amp;#039; as it is.&lt;br /&gt;
# Make the program ask for a filename (the input file in the following exercises), and display the file on the screen.&lt;br /&gt;
# Construct a program that counts the number of lines in the input file, and displays the result. Try it with the file &amp;#039;&amp;#039;ex1.dat&amp;#039;&amp;#039;. There are 1675 lines.&lt;br /&gt;
# Now make a Python program that sums numbers from a input file and displays the sum of the numbers. I have created 3 files with the columns from &amp;#039;&amp;#039;ex1.dat&amp;#039;&amp;#039;; &amp;#039;&amp;#039;ex1_1.dat&amp;#039;&amp;#039;, &amp;#039;&amp;#039;ex1_2.dat&amp;#039;&amp;#039; &amp;amp; &amp;#039;&amp;#039;ex1_3.dat&amp;#039;&amp;#039;. Use the 3 files as input and see the sums. The sums are approx. Col 1; -904.4143, Col 2; 482.8410, Col 3; 292.05150 for the three columns.&lt;br /&gt;
# Based on the previous program, now make a new one that calculates the mean value of the columns. Create your own test file with some numbers (where you know what the result should be) and feed that to the program.&lt;br /&gt;
# Now make a program that counts the number of positive and negative numbers in an input file. Also count the zeroes in the column, if there are any. Display the result.&lt;br /&gt;
# Now make a program that finds the maximum number in a column. Display the result. This is quite tricky. Hint: &amp;#039;&amp;#039;&amp;#039;None&amp;#039;&amp;#039;&amp;#039; could be useful.&lt;br /&gt;
# Now make a program that finds the minimum number in a column and display the result.&lt;br /&gt;
# It begins to get trivial. Now make a program that does all of the above, that is; calculate the sum, the number of lines, the mean value, the number of positive, negative and zero numbers, the maximum and the minimum value. You can only read the file once. Display the all results clearly so there is no doubt about what you display.&lt;br /&gt;
&lt;br /&gt;
== Exercises for extra practice ==&lt;br /&gt;
* Ask for some input - it could be a word or a number or a sentence. Then ask for a file name - any file will do, but &amp;#039;&amp;#039;mixedlines.txt&amp;#039;&amp;#039; or &amp;#039;&amp;#039;ex5.acc&amp;#039;&amp;#039; are good. Now read the file and determine if one (or more) of the lines in the file matches your input precisely. Display &amp;quot;Match&amp;quot; or &amp;quot;No  match&amp;quot; accordingly. Hint: A line from a file has a newline at the end, but using the &amp;#039;&amp;#039;&amp;#039;input&amp;#039;&amp;#039;&amp;#039; function does not result in this newline.&lt;br /&gt;
* For extra difficulty, do the same program once more, but this time, it should only say &amp;quot;Match&amp;quot; or &amp;quot;No match&amp;quot; once, no matter how many matches there are. Make your own test file, with lots of the same number or word. If you already solved this in above exercise - good for you.&lt;br /&gt;
* Ask for 2 integers. Now print the first 20 numbers of the [https://en.wikipedia.org/wiki/Fibonacci_number Fibonacci sequence] given by those numbers. If the input is 1 &amp;amp; 3, the output would be 1 3 4 7 11 18 29 47 etc.. The next number is the sum of the 2 previous.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
</feed>