<?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=Python_Input-Output</id>
	<title>Python Input-Output - 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=Python_Input-Output"/>
	<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22101/index.php?title=Python_Input-Output&amp;action=history"/>
	<updated>2026-04-23T16:36: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=Python_Input-Output&amp;diff=78&amp;oldid=prev</id>
		<title>WikiSysop: /* Exercises for extra practice */</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22101/index.php?title=Python_Input-Output&amp;diff=78&amp;oldid=prev"/>
		<updated>2024-10-30T09:19:27Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Exercises for extra practice&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:19, 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-l53&quot;&gt;Line 53:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 53:&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;* Ask for 2 input file names (&amp;#039;&amp;#039;ex1.acc&amp;#039;&amp;#039;  &amp;amp; &amp;#039;&amp;#039;ex1.dat&amp;#039;&amp;#039; are good) and an output file name. Copy (read and write) the input files into the output file, one after the other.&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;* Ask for 2 input file names (&amp;#039;&amp;#039;ex1.acc&amp;#039;&amp;#039;  &amp;amp; &amp;#039;&amp;#039;ex1.dat&amp;#039;&amp;#039; are good) and an output file name. Copy (read and write) the input files into the output file, one after the other.&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;* Ask for 2 input file names (&amp;#039;&amp;#039;ex1.acc&amp;#039;&amp;#039;  &amp;amp; &amp;#039;&amp;#039;ex1.dat&amp;#039;&amp;#039; are good) and an output file name. Now copy/print the lines in the input files into the output file so that the first line of each input file are merged together with a tab and becomes the first line of the output. Continue that way with all the lines in the input file. A mental picture of what is supposed to happen is this: Imagine the 2 input files to be two pieces of paper with lines. In the exercise before the papers were put one after the other in the output. In this exercise the papers are put next to each other (sideways) in the output.&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;* Ask for 2 input file names (&amp;#039;&amp;#039;ex1.acc&amp;#039;&amp;#039;  &amp;amp; &amp;#039;&amp;#039;ex1.dat&amp;#039;&amp;#039; are good) and an output file name. Now copy/print the lines in the input files into the output file so that the first line of each input file are merged together with a tab and becomes the first line of the output. Continue that way with all the lines in the input file. A mental picture of what is supposed to happen is this: Imagine the 2 input files to be two pieces of paper with lines. In the exercise before the papers were put one after the other in the output. In this exercise the papers are put next to each other (sideways) in the output.&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;* Read the &#039;&#039;mixedlines.txt&#039;&#039; and count how many long lines there are in the file. A long line has more than 30 chars.&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;* Read the &#039;&#039;mixedlines.txt&#039;&#039; and count how many long lines there are in the file. A long line has more than 30 chars. &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;(60)&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;* In &#039;&#039;mixedlines.txt&#039;&#039; how many occurrences for &quot;rna&quot; can you find?&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;* In &#039;&#039;mixedlines.txt&#039;&#039; how many occurrences for &quot;rna&quot; can you find? &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;(7)&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;* In &#039;&#039;mixedlines.txt&#039;&#039; how many lines contain &quot;rna&quot;?&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;* In &#039;&#039;mixedlines.txt&#039;&#039; how many lines contain &quot;rna&quot;? &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;(6)&lt;/ins&gt;&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=Python_Input-Output&amp;diff=77&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=Python_Input-Output&amp;diff=77&amp;oldid=prev"/>
		<updated>2024-10-30T09:18:21Z</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:18, 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-l32&quot;&gt;Line 32:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 32:&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 counts the number of negative numbers in &#039;&#039;ex1.dat&#039;&#039; file. 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;# Write a program that counts the number of negative numbers in &#039;&#039;ex1.dat&#039;&#039; file. Display the result&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;, which is 3272. Hint: Think about what defines a negative number&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;# Write a program that converts temperatures from Fahrenheit to Celsius or visa versa given input like &amp;quot;36F&amp;quot; of &amp;quot;15C&amp;quot; ( F = (C * 9/5) + 32 ).&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;# Write a program that converts temperatures from Fahrenheit to Celsius or visa versa given input like &amp;quot;36F&amp;quot; of &amp;quot;15C&amp;quot; ( F = (C * 9/5) + 32 ).&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;# &amp;lt;font color=&amp;quot;#AA00FF&amp;quot;&amp;gt;Read the file &amp;#039;&amp;#039;orphans.sp&amp;#039;&amp;#039; and find all accession numbers (and only the accession numbers), save them in another file of your choosing. Hint: an accession number might look like this AB000114.CDS.1 or like this AB000114 or like this AB000114.CDS.3. CDS means CoDing Sequence followed by a number. If the accession number contains the CDS part, consider .CDS.1 as a part of the accession number. Accession numbers differ in length for historical reasons. You can assume that the accession number comes straight after the &amp;#039;&amp;#039;&amp;#039;&amp;gt;&amp;#039;&amp;#039;&amp;#039;, which is first on the line. Notice that this is a purple exercise; You have make the pseudo code first and hand it in as part of the exercise.&amp;lt;/font&amp;gt;&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;# &amp;lt;font color=&amp;quot;#AA00FF&amp;quot;&amp;gt;Read the file &amp;#039;&amp;#039;orphans.sp&amp;#039;&amp;#039; and find all accession numbers (and only the accession numbers), save them in another file of your choosing. Hint: an accession number might look like this AB000114.CDS.1 or like this AB000114 or like this AB000114.CDS.3. CDS means CoDing Sequence followed by a number. If the accession number contains the CDS part, consider .CDS.1 as a part of the accession number. Accession numbers differ in length for historical reasons. You can assume that the accession number comes straight after the &amp;#039;&amp;#039;&amp;#039;&amp;gt;&amp;#039;&amp;#039;&amp;#039;, which is first on the line. Notice that this is a purple exercise; You have make the pseudo code first and hand it in as part of the exercise.&amp;lt;/font&amp;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 you must analyze the AT/GC content of the DNA in the file &#039;&#039;dna.dat&#039;&#039;. You must count all A, T, C and G, 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 you must analyze the AT/GC content of the DNA in the file &#039;&#039;dna.dat&#039;&#039;. You must count all A, T, C and G, and display the result&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;: A: 333 T: 303 C: 454 G: 469&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;# This and the rest of the exercises aims to make the reverse complement string (called &amp;quot;complement strand&amp;quot;) of DNA. They are building up in complexity, but every exercise must stand alone, i.e. NOT be dependent on what the previous exercises achieved but start over every time in order to be a coherent product.&amp;lt;br&amp;gt;There is some human DNA in the &amp;#039;&amp;#039;dna.dat&amp;#039;&amp;#039; file. Read the file and put all the DNA in one variable. Now complement the DNA and store it in other variable. Display and ensure that it works. HINT: Complementing means changing all A&amp;#039;s to T&amp;#039;s, T&amp;#039;s to A&amp;#039;s, C&amp;#039;s to G&amp;#039;s and G&amp;#039;s to C&amp;#039;s.&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;# This and the rest of the exercises aims to make the reverse complement string (called &amp;quot;complement strand&amp;quot;) of DNA. They are building up in complexity, but every exercise must stand alone, i.e. NOT be dependent on what the previous exercises achieved but start over every time in order to be a coherent product.&amp;lt;br&amp;gt;There is some human DNA in the &amp;#039;&amp;#039;dna.dat&amp;#039;&amp;#039; file. Read the file and put all the DNA in one variable. Now complement the DNA and store it in other variable. Display and ensure that it works. HINT: Complementing means changing all A&amp;#039;s to T&amp;#039;s, T&amp;#039;s to A&amp;#039;s, C&amp;#039;s to G&amp;#039;s and G&amp;#039;s to C&amp;#039;s.&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 reverse the DNA after complementing it. Reverse means last letter (base) should be the first, next to last should be the second, and so forth. 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;# Now reverse the DNA after complementing it. Reverse means last letter (base) should be the first, next to last should be the second, and so forth. Display.&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=Python_Input-Output&amp;diff=18&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: Pseudocode and Comments |Next: Exceptions and Bug Handling |} == Required course material for the lesson == Powerpoint: [https://teaching.healthtech.dtu.dk/material/22101/22101_06-InputOutput.ppt Input, output, libraries and strings]&lt;br&gt; Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=0f769984-a650-444f-bb2c-af27012e79b3 File reading and writing]&lt;br&gt; Video: [...&quot;</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22101/index.php?title=Python_Input-Output&amp;diff=18&amp;oldid=prev"/>
		<updated>2024-03-01T15:44:07Z</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/Pseudocode_and_Comments&quot; title=&quot;Pseudocode and Comments&quot;&gt;Pseudocode and Comments&lt;/a&gt; |Next: &lt;a href=&quot;/22101/index.php/Exceptions_and_Bug_Handling&quot; title=&quot;Exceptions and Bug Handling&quot;&gt;Exceptions and Bug Handling&lt;/a&gt; |} == Required course material for the lesson == Powerpoint: [https://teaching.healthtech.dtu.dk/material/22101/22101_06-InputOutput.ppt Input, output, libraries and strings]&amp;lt;br&amp;gt; Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=0f769984-a650-444f-bb2c-af27012e79b3 File reading and writing]&amp;lt;br&amp;gt; Video: [...&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: [[Pseudocode and Comments]]&lt;br /&gt;
|Next: [[Exceptions and Bug Handling]]&lt;br /&gt;
|}&lt;br /&gt;
== Required course material for the lesson ==&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22101/22101_06-InputOutput.ppt Input, output, libraries and strings]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=0f769984-a650-444f-bb2c-af27012e79b3 File reading and writing]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=67d3cdd4-7843-4a31-a53d-af27012e62de Python libraries]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=4ae29c7b-972d-4441-863a-af27012e4042 Strings and substrings]&amp;lt;br&amp;gt;&lt;br /&gt;
Resource: [[Biological knowledge needed in the course]]&amp;lt;br&amp;gt;&lt;br /&gt;
Resource: [[Example code - Input Output]]&amp;lt;br&amp;gt;&lt;br /&gt;
Resource: [https://teaching.healthtech.dtu.dk/material/22101/clean_code.html Clean Code] Every time you read it, you will take something from it.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Video: [https://video.dtu.dk/media/22110-lesson04-LiveCoding/0_fua9gb78 Live Coding] FAILED&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=0e86b23b-eabd-4a51-90cf-af1500a36b33 Python Pep Talk] Thursday&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/36610/python_peptalk.pptx Python pep talk by Line Egerod Lund] Thursday&amp;lt;br&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Subjects covered ==&lt;br /&gt;
;Using files&lt;br /&gt;
:&amp;#039;&amp;#039;open&amp;#039;&amp;#039; which opens a file (makes it ready) for reading or writing.&lt;br /&gt;
:&amp;#039;&amp;#039;close&amp;#039;&amp;#039; which ends the reading/writing.&lt;br /&gt;
:&amp;#039;&amp;#039;readline&amp;#039;&amp;#039;, which reads a line from a file handle.&lt;br /&gt;
:&amp;#039;&amp;#039;write&amp;#039;&amp;#039;, which writes a line to a file (handle). &lt;br /&gt;
;String manipulation&lt;br /&gt;
:&amp;#039;&amp;#039;len&amp;#039;&amp;#039;, which tells how long a string is.&lt;br /&gt;
:Slicing.&lt;br /&gt;
;Standard library functions&lt;br /&gt;
:&amp;#039;&amp;#039;sys.exit&amp;#039;&amp;#039; terminates the program.&lt;br /&gt;
:&amp;#039;&amp;#039;os.system&amp;#039;&amp;#039;, which submits jobs to the operating system.&lt;br /&gt;
&lt;br /&gt;
== Exercises to be handed in ==&lt;br /&gt;
# Write a program that counts the number of negative numbers in &amp;#039;&amp;#039;ex1.dat&amp;#039;&amp;#039; file. Display the result.&lt;br /&gt;
# Write a program that converts temperatures from Fahrenheit to Celsius or visa versa given input like &amp;quot;36F&amp;quot; of &amp;quot;15C&amp;quot; ( F = (C * 9/5) + 32 ).&lt;br /&gt;
# &amp;lt;font color=&amp;quot;#AA00FF&amp;quot;&amp;gt;Read the file &amp;#039;&amp;#039;orphans.sp&amp;#039;&amp;#039; and find all accession numbers (and only the accession numbers), save them in another file of your choosing. Hint: an accession number might look like this AB000114.CDS.1 or like this AB000114 or like this AB000114.CDS.3. CDS means CoDing Sequence followed by a number. If the accession number contains the CDS part, consider .CDS.1 as a part of the accession number. Accession numbers differ in length for historical reasons. You can assume that the accession number comes straight after the &amp;#039;&amp;#039;&amp;#039;&amp;gt;&amp;#039;&amp;#039;&amp;#039;, which is first on the line. Notice that this is a purple exercise; You have make the pseudo code first and hand it in as part of the exercise.&amp;lt;/font&amp;gt;&lt;br /&gt;
# Now you must analyze the AT/GC content of the DNA in the file &amp;#039;&amp;#039;dna.dat&amp;#039;&amp;#039;. You must count all A, T, C and G, and display the result.&lt;br /&gt;
# This and the rest of the exercises aims to make the reverse complement string (called &amp;quot;complement strand&amp;quot;) of DNA. They are building up in complexity, but every exercise must stand alone, i.e. NOT be dependent on what the previous exercises achieved but start over every time in order to be a coherent product.&amp;lt;br&amp;gt;There is some human DNA in the &amp;#039;&amp;#039;dna.dat&amp;#039;&amp;#039; file. Read the file and put all the DNA in one variable. Now complement the DNA and store it in other variable. Display and ensure that it works. HINT: Complementing means changing all A&amp;#039;s to T&amp;#039;s, T&amp;#039;s to A&amp;#039;s, C&amp;#039;s to G&amp;#039;s and G&amp;#039;s to C&amp;#039;s.&lt;br /&gt;
# Now reverse the DNA after complementing it. Reverse means last letter (base) should be the first, next to last should be the second, and so forth. Display.&lt;br /&gt;
# Now write the DNA in the file &amp;#039;&amp;#039;revdna.dat&amp;#039;&amp;#039;. Make it look nice, just like &amp;#039;&amp;#039;dna.dat&amp;#039;&amp;#039;, i.e. 60 letters per line. This does NOT mean that you should insert newlines in the variable containing your complement strand (contamination of clean data you possibly should use later in the program). It just means that DNA in the output file must have 60 chars per line, just as in the input file.&lt;br /&gt;
# In the file &amp;#039;&amp;#039;dna.fsa&amp;#039;&amp;#039; is the same human DNA in FASTA format. This format is VERY often used in bioinformatics. Look at it using less and get used to the format. Observe the first line which starts with a &amp;gt; and identifies the sequence. The name (AB000410 in this case) MUST uniquely identify a sequence in the file. This is a DNA (actually mRNA) sequence taken from the GenBank database. Now make a program that reverse complements the sequence and writes it into the file &amp;#039;&amp;#039;revdna.fsa&amp;#039;&amp;#039; just like you did in previous assignments. This time you have to keep the first identifying line, so the sequence can be identified. You must add &amp;#039;ComplementStrand&amp;#039; in the end of that line, though, so you later know that it is the complement strand.&amp;lt;br&amp;gt;Summary: Keep the first line and reverse complement the sequence.&lt;br /&gt;
&lt;br /&gt;
== Exercises for extra practice ==&lt;br /&gt;
Slicing: the act of taking out a substring (part of a string) from a string. Learning the technique of &amp;quot;walking the line&amp;quot;.&lt;br /&gt;
* Input a line from the keyboard. Count the number of stars * on the line. Display. Example: DG*GDG*GSD*GG&amp;lt;br&amp;gt;Star count: 3&lt;br /&gt;
* Input a line from the keyboard. Now print the characters on the line vertically, i.e. one char per line downwards. Example: ABC&amp;lt;br&amp;gt;A&amp;lt;br&amp;gt;B&amp;lt;br&amp;gt;C&lt;br /&gt;
* Input a line from the keyboard. Now print 2 characters on the line vertically, i.e. two char per line downwards. Advance 1 char at a time. Example: ABC&amp;lt;br&amp;gt;AB&amp;lt;br&amp;gt;BC&lt;br /&gt;
* Input a line from the keyboard. Now print 2 characters on the line vertically, i.e. two char per line downwards. Advance 2 chars at a time. If there is a leftover char at the end of the string, print it. Example: ABCDE&amp;lt;br&amp;gt;AB&amp;lt;br&amp;gt;CD&amp;lt;br&amp;gt;E&lt;br /&gt;
* Input a line from the keyboard. Now print 2 characters on the line vertically, i.e. two char per line downwards. Advance 2 chars at a time. If there is leftover char at the end of the string, do NOT print it. Example: ABCDE&amp;lt;br&amp;gt;AB&amp;lt;br&amp;gt;CD&lt;br /&gt;
* Input a DNA line from the keyboard. Now print 3 characters (a codon) on the line vertically, i.e. three char per line downwards. Advance 3 chars at a time. If there is a leftover DNA that can not constitute a codon at the end of the string, do NOT print it. Example: TACCATCGATCAG&amp;lt;br&amp;gt;TAC&amp;lt;br&amp;gt;CAT&amp;lt;br&amp;gt;CGA&amp;lt;br&amp;gt;TCA&lt;br /&gt;
* Input a sentence (a line) from the keyboard. Write every word on its own line. Example: The answer is 42.&amp;lt;br&amp;gt;The&amp;lt;br&amp;gt;answer&amp;lt;br&amp;gt;is&amp;lt;br&amp;gt;42.&lt;br /&gt;
Opening files.&lt;br /&gt;
* Ask for 2 input file names (&amp;#039;&amp;#039;ex1.acc&amp;#039;&amp;#039;  &amp;amp; &amp;#039;&amp;#039;ex1.dat&amp;#039;&amp;#039; are good) and an output file name. Copy (read and write) the input files into the output file, one after the other.&lt;br /&gt;
* Ask for 2 input file names (&amp;#039;&amp;#039;ex1.acc&amp;#039;&amp;#039;  &amp;amp; &amp;#039;&amp;#039;ex1.dat&amp;#039;&amp;#039; are good) and an output file name. Now copy/print the lines in the input files into the output file so that the first line of each input file are merged together with a tab and becomes the first line of the output. Continue that way with all the lines in the input file. A mental picture of what is supposed to happen is this: Imagine the 2 input files to be two pieces of paper with lines. In the exercise before the papers were put one after the other in the output. In this exercise the papers are put next to each other (sideways) in the output.&lt;br /&gt;
* Read the &amp;#039;&amp;#039;mixedlines.txt&amp;#039;&amp;#039; and count how many long lines there are in the file. A long line has more than 30 chars.&lt;br /&gt;
* In &amp;#039;&amp;#039;mixedlines.txt&amp;#039;&amp;#039; how many occurrences for &amp;quot;rna&amp;quot; can you find?&lt;br /&gt;
* In &amp;#039;&amp;#039;mixedlines.txt&amp;#039;&amp;#039; how many lines contain &amp;quot;rna&amp;quot;?&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
</feed>