<?xml version="1.0" encoding="utf-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Forum Bauen und Umwelt - Python im Browser</title>
<link>https://bauforum.wirklichewelt.de/</link>
<description>Das Bauforum</description>
<language>de</language>
<item>
<title>Python im Browser</title>
<content:encoded><![CDATA[<p>Auf <a href="http://syntensity.com/static/python.html" target="_blank">http://syntensity.com/static/python.html</a> gibt es einen Python-Interpreter, der in jedem aktuellen javascriptfähigen Browser läuft. Damit lassen sich schnell mal eben ein paar Programmzeilen ausführen, auch wenn der Rechner, an dem man sitzt, über keine lokale Python-Installation verfügt.</p>
<p>Für „richtige“ Programme ist die <a href="https://github.com/kripken/emscripten/wiki" target="_blank">Demo</a> nicht zu gebrauchen. So gibt es beispielsweise keine Eingabemöglichkeit mittels input(). Der Interpreter kann auch keine Module (außer sys) einbinden, was die Verwendung der wichtigen Bibliothek math ausschließt. Zudem verwendet er die Python-Version 2.7, was zu weiteren Einschränkungen führt, wenn man Python 3 gewohnt ist. So sind beispielsweise keine Umlaute in Variablen- und Funktionsnamen erlaubt, die Division von Ganzzahlen ergibt immer ein ganzzahliges Ergebnis und Zeichenketten dürfen nicht alle Unicode-Zeichen enthalten.</p>
<p>Für die im Foreneintrag <a href="http://bauforum.wirklichewelt.de/index.php?nr=8525" target="_blank">Gaußsche Osterformel in Python 3</a> vorgestellte Berechnung des Osterdatums reicht die Website aber aus. Die letzten drei Zeilen müssen dazu an die alte Pythonversion angepasst werden. Die input-Anweisung muss durch eine Variablenzuweisung ersetzt werden und die print-Funktion mit Klammern wird zur print-Anweisung ohne Klammern:</p>
<pre class="python" style="font-family:monospace;"><ol><li style="background:#f5f5f5;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #ff7700;">def</span> ostern<span style="color: black;">&#40;</span>jahr<span style="color: black;">&#41;</span>:</div></li><li style="background:#f9f9f9;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">    A <span style="color: #000;">=</span> jahr%<span style="color: #008;">19</span></div></li><li style="background:#f5f5f5;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">    K <span style="color: #000;">=</span> jahr//<span style="color: #008;">100</span></div></li><li style="background:#f9f9f9;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">    M <span style="color: #000;">=</span> <span style="color: #008;">15</span>+<span style="color: black;">&#40;</span><span style="color: #008;">3</span>*K+<span style="color: #008;">3</span><span style="color: black;">&#41;</span>//<span style="color: #008;">4</span>-<span style="color: black;">&#40;</span><span style="color: #008;">8</span>*K+<span style="color: #008;">13</span><span style="color: black;">&#41;</span>//<span style="color: #008;">25</span></div></li><li style="background:#f5f5f5;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">    D <span style="color: #000;">=</span> <span style="color: black;">&#40;</span><span style="color: #008;">19</span>*A+M<span style="color: black;">&#41;</span>%<span style="color: #008;">30</span></div></li><li style="background:#f9f9f9;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">    S <span style="color: #000;">=</span> <span style="color: #008;">2</span>-<span style="color: black;">&#40;</span><span style="color: #008;">3</span>*K+<span style="color: #008;">3</span><span style="color: black;">&#41;</span>//<span style="color: #008;">4</span></div></li><li style="background:#f5f5f5;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">    R <span style="color: #000;">=</span> D//<span style="color: #008;">29</span>+<span style="color: black;">&#40;</span>D//<span style="color: #008;">28</span>-D//<span style="color: #008;">29</span><span style="color: black;">&#41;</span>*<span style="color: black;">&#40;</span>A//<span style="color: #008;">11</span><span style="color: black;">&#41;</span></div></li><li style="background:#f9f9f9;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">    OG <span style="color: #000;">=</span> <span style="color: #008;">21</span>+D+R</div></li><li style="background:#f5f5f5;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">    SZ <span style="color: #000;">=</span> <span style="color: #008;">7</span>-<span style="color: black;">&#40;</span>jahr+jahr//<span style="color: #008;">4</span>+S<span style="color: black;">&#41;</span>%<span style="color: #008;">7</span></div></li><li style="background:#f9f9f9;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">    OE <span style="color: #000;">=</span> <span style="color: #008;">7</span>-<span style="color: black;">&#40;</span>OG-SZ<span style="color: black;">&#41;</span>%<span style="color: #008;">7</span></div></li><li style="background:#f5f5f5;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">    OS <span style="color: #000;">=</span> <span style="color: black;">&#40;</span>OG+OE<span style="color: black;">&#41;</span></div></li><li style="background:#f9f9f9;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">    <span style="color: #ff7700;">if</span> OS<span style="color: #000;">&gt;</span><span style="color: #008;">31</span>:</div></li><li style="background:#f5f5f5;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">        <span style="color: #ff7700;">return</span><span style="color: black;">&#40;</span><span style="color: #808;">str</span><span style="color: black;">&#40;</span>OS-<span style="color: #008;">31</span><span style="color: black;">&#41;</span>+<span style="color: #080;">&quot;. April&quot;</span><span style="color: black;">&#41;</span></div></li><li style="background:#f9f9f9;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">    <span style="color: #ff7700;">else</span>:</div></li><li style="background:#f5f5f5;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">        <span style="color: #ff7700;">return</span><span style="color: black;">&#40;</span><span style="color: #808;">str</span><span style="color: black;">&#40;</span>OS<span style="color: black;">&#41;</span>+<span style="color: #080;">&quot;. März&quot;</span><span style="color: black;">&#41;</span></div></li><li style="background:#f9f9f9;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li style="background:#f5f5f5;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #808;">print</span> <span style="color: #080;">&quot;Berechnung des Osterdatums&quot;</span></div></li><li style="background:#f9f9f9;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #ff7700;">for</span> jahr <span style="color: #ff7700;">in</span> <span style="color: #808;">range</span><span style="color: black;">&#40;</span><span style="color: #008;">1583</span><span style="color: #000;">,</span><span style="color: #008;">2200</span><span style="color: black;">&#41;</span>:</div></li><li style="background:#f5f5f5;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">    <span style="color: #808;">print</span> <span style="color: #080;">&quot;Im Jahre &quot;</span>+<span style="color: #808;">str</span><span style="color: black;">&#40;</span>jahr<span style="color: black;">&#41;</span>+<span style="color: #080;">&quot; fällt der Ostersonntag auf den &quot;</span>+ostern<span style="color: black;">&#40;</span>jahr<span style="color: black;">&#41;</span>+<span style="color: #080;">&quot;.&quot;</span></div></li></ol></pre>]]></content:encoded>
<link>https://bauforum.wirklichewelt.de/index.php?id=8689</link>
<guid>https://bauforum.wirklichewelt.de/index.php?id=8689</guid>
<pubDate>Tue, 31 May 2011 14:39:59 +0000</pubDate>
<category>Software</category><dc:creator>Martin Vogel</dc:creator>
</item>
</channel>
</rss>
