http://wiki.math.bme.hu/history/Informatika2-2014/Eloadas_Python/1ZH?feed=atom&
Informatika2-2014/Eloadas Python/1ZH - Laptörténet
2024-03-28T14:48:16Z
Az oldal laptörténete a wikiben
MediaWiki 1.18.1
http://wiki.math.bme.hu/index.php?title=Informatika2-2014/Eloadas_Python/1ZH&diff=10110&oldid=prev
Wettl, 2014. április 22., 21:12-n
2014-04-22T21:12:26Z
<p></p>
<table class='diff diff-contentalign-left'>
<col class='diff-marker' />
<col class='diff-content' />
<col class='diff-marker' />
<col class='diff-content' />
<tr valign='top'>
<td colspan='2' style="background-color: white; color:black;">←Régebbi változat</td>
<td colspan='2' style="background-color: white; color:black;">A lap 2014. április 22., 21:12-kori változata</td>
</tr><tr><td colspan="2" class="diff-lineno">302. sor:</td>
<td colspan="2" class="diff-lineno">302. sor:</td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>     def __repr__(self):</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>     def __repr__(self):</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>         return "{:.5f}{:+.5f}i{:+.5f}j{:+.5f}k".format(self.re, self.i, self.j, self.k)</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>         return "{:.5f}{:+.5f}i{:+.5f}j{:+.5f}k".format(self.re, self.i, self.j, self.k)</div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;"></python></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">Használata:</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;"><python></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">>>> q1 = Quaternion(1, 2, 3, 4)</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">>>> q2 = Quaternion(-1, 2, 0, -4)</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">>>> print q1</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">1.00000+2.00000i+3.00000j+4.00000k</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">>>> print q2</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">-1.00000+2.00000i+0.00000j-4.00000k</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">>>> q1 + q2</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">0.00000+4.00000i+3.00000j+0.00000k</ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div></python></div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div></python></div></td></tr>
</table>
Wettl
http://wiki.math.bme.hu/index.php?title=Informatika2-2014/Eloadas_Python/1ZH&diff=10109&oldid=prev
Wettl, 2014. április 22., 21:07-n
2014-04-22T21:07:22Z
<p></p>
<table class='diff diff-contentalign-left'>
<col class='diff-marker' />
<col class='diff-content' />
<col class='diff-marker' />
<col class='diff-content' />
<tr valign='top'>
<td colspan='2' style="background-color: white; color:black;">←Régebbi változat</td>
<td colspan='2' style="background-color: white; color:black;">A lap 2014. április 22., 21:07-kori változata</td>
</tr><tr><td colspan="2" class="diff-lineno">212. sor:</td>
<td colspan="2" class="diff-lineno">212. sor:</td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>'''8.'''  </div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>'''8.''' <ins class="diffchange diffchange-inline">Egészítsük ki az alábbi kódot, hogy a megfelelő kimenetet produkálja:</ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>'''Megoldás'''</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>'''Megoldás'''</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div><python></div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div><python></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">>>> def egysegvektor(dim = 2, e = 1):</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">...    l = []</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">...    for i in range(dim):</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">...        l.append(0)</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">...    l[e-1] = 1</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">...    return l</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">... </ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">>>> print egysegvektor(4, 2)</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">[0, 1, 0, 0]</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">>>> print egysegvektor(5, 4)</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">[0, 0, 0, 1, 0]</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">>>> print egysegvektor(3, 1)</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">[1, 0, 0]</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">>>> print egysegvektor(2)</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">[1, 0]</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">>>> print egysegvektor(3)</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">[1, 0, 0]</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">>>> print egysegvektor()</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">[1, 0]</ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div></python></div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div></python></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>'''9.'''  </div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>'''9.''' <ins class="diffchange diffchange-inline">Mely adattípusoknak létezik ''hash'' értéke?</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div> </div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline">'''Megoldás'''</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div> </div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline">Létezik: int  bool float tuple string</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div> </div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline">Nem létezik: list dict</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div> </div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div> </div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline">'''10.''' Mit írnak ki a következő kódok?</ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>'''Megoldás'''</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>'''Megoldás'''</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div><python></div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div><python></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">>>> print [(x, y) </ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">...          for y in range(5) </ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">...          for x in range(5) </ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">...          if abs(x - y) == 1]</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">[(1, 0), (0, 1), (2, 1), (1, 2), (3, 2), (2, 3), (4, 3), (3, 4)]</ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div></python></div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div></python></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>'''<del class="diffchange diffchange-inline">10</del>.'''  </div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline"><python></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline">>>> print [p for p in range(30) </ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline">...          if len([x for x in range(1, p + 1) </ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline">...                    if p % x == 0]) == 2]</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline">[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline"></python></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div> </div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline"><python></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline">>>> print map(lambda x: x * 2, [1, 2, 5])</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline">[2, 4, 10]</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline"></python></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div> </div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div> </div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>'''<ins class="diffchange diffchange-inline">11</ins>.''' <ins class="diffchange diffchange-inline">A kvaterniók a komplex számtest bővítésével kapott algebrai struktúra elemei. Hasonlóan ahhoz, ahogy a komplex számokat az $R^2$ elemeivel, a kvaterniókat $R^4$ elemeivel reprezentálhatjuk. A kvaterniók szokásos reprezentációja: a+bi+cj+dk, ahol i, j és k imaginárius egységek és a, b, c, d eleme R (továbbá i^2=j^2=k^2=-1, ij=k, jk=i, ki=j).</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div> </div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline">Írjunk egy ''Quaternion'' nevű osztályt, melynek példányai kvaterniók. Az osztálydefinícióban szerepeljen az alábbi 4 metódus:</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline">* ''__init__'': a ''q = Quaternion(a,b,c,d)'' kód hatására létrehozza az a+bi+cj+dk kvaterniót (egy kvaterniót 4 tulajdonság fogja jellemezni).</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline">* ''__add__'': összead két kvaterniót. A kvaterniók összeadása megfelel a 4-dimenziós vektorok összeadásának.</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline">* ''__mul__'': összeszoroz két kvaterniót. A szorzás szabálya: <math>(a+bi+cj+dk)\cdot(A+Bi+Cj+Dk)</math> szorzat értéke</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline"><math>aA-bB-cC-dD +(aB+bA+cD-dC)i+(aC-bD+cA+dB)j+(aD+bC-cB+dA)k</math></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline">* ''__repr__'': a (format metódus segítségével) a kvaterniót az $a+bi+cj+dk$ alaknak megfelelően írja ki. Például a ''q = Quaternion(1.1, 2.3, -3, 4.6)'' kvaternió megjelenítése ''1.10000+2.30000i-3.00000j+4.60000k''.</ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>'''Megoldás'''</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>'''Megoldás'''</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div><python></div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div><python></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">class Quaternion(object):</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">    """Calculating with quaternion"""</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">    def __init__(self, a, b, c, d):</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">        self.re, self.i, self.j, self.k = a, b, c, d</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">    def __add__(self, q):</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">        return Quaternion(self.re+q.re, self.i+q.i, self.j+q.j, self.k+q.k)</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">    def __mul__(self, q):</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">        a, b, c, d = self.re, self.i, self.j, self.k</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">        A, B, C, D = q.re, q.i, q.j, q.k</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">        return Quaternion(a*A - b*B - c*C - d*D,</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">                          a*B + b*A + c*D - d*C,</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">                          a*C - b*D + c*A + d*B,</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">                          a*D + b*C - c*B + d*A)</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">    def __repr__(self):</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">        return "{:.5f}{:+.5f}i{:+.5f}j{:+.5f}k".format(self.re, self.i, self.j, self.k)</ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div></python></div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div></python></div></td></tr>
</table>
Wettl
http://wiki.math.bme.hu/index.php?title=Informatika2-2014/Eloadas_Python/1ZH&diff=10108&oldid=prev
Wettl, 2014. április 22., 20:42-n
2014-04-22T20:42:38Z
<p></p>
<a href="http://wiki.math.bme.hu/index.php?title=Informatika2-2014/Eloadas_Python/1ZH&diff=10108&oldid=10107">Változtatások megtekintése</a>
Wettl
http://wiki.math.bme.hu/index.php?title=Informatika2-2014/Eloadas_Python/1ZH&diff=10107&oldid=prev
Wettl: Új oldal, tartalma: „==1. ZH== '''1.''' Írjunk fel egy reguláris kifejezést, mely pontosan azokra a két számból álló karakterláncokra illeszkedik, melyek oszthatók 3-mal. A regul…”
2014-04-22T20:07:02Z
<p>Új oldal, tartalma: „==1. ZH== '''1.''' Írjunk fel egy reguláris kifejezést, mely pontosan azokra a két számból álló karakterláncokra illeszkedik, melyek oszthatók 3-mal. A regul…”</p>
<p><b>Új lap</b></p><div>==1. ZH==<br />
<br />
'''1.''' Írjunk fel egy reguláris kifejezést, mely pontosan azokra a két számból álló karakterláncokra illeszkedik, melyek oszthatók 3-mal. A reguláris kifejezés tehát illeszkedjen a "00", "03", "12", "24", "99" karaterláncokra, de ne illeszkedjen a "01", "98", "0a", "ab" karakterláncokra (az egyszerűség kedvéért az előtte lévő és az utána következő karakterekkel nem kell foglalkozni).<br />
<br />
'''Megoldás'''<br />
<br />
<python><br />
[0369][0369]|[147][258]|[258][147]<br />
</python><br />
<br />
'''2.''' Írjunk kódot, mely egy karakterláncból mozaikszót képez. A mozaikszó a karakterlánc minden nagy betűvel kezdődő szavából csak a nagy betűk megtartásával képződik. A karakterlánc csak az angol ábécé betűit és szóközöket tartalmaz. Használjuk a 're' modul 'sub' függvényét, vagy egy regexp objektum 'sub' metódusát a megoldáshoz. A kód példa bemenetekre adott válaszai: \pont2<br />
<br />
"American Mathematical Society" --> "AMS"<br />
<br />
"Masters of Business Administration" --> "MBA"<br />
<br />
'''Két megoldás'''<br />
<br />
<python><br />
>>> import re<br />
>>> line = 'Masters of Business Administration'<br />
>>> prog = re.compile("[^A-Z]")<br />
>>> prog.sub("", line)<br />
'MBA'<br />
</python><br />
<br />
<python><br />
>>> import re<br />
>>> line = 'Masters of Business Administration'<br />
>>> re.sub("[^A-Z]", "", line)<br />
'MBA'<br />
</python><br />
<br />
'''Két másik megoldás'''<br />
<br />
<python><br />
>>> import re<br />
>>> line = 'Masters of Business Administration'<br />
>>> prog = re.compile("([A-Z])[a-z ]+")<br />
>>> prog.sub(r"\1", line)<br />
'MBA'<br />
</python><br />
<br />
<python><br />
>>> import re<br />
>>> line = 'Masters of Business Administration'<br />
>>> re.sub("([A-Z])[a-z ]+", r"\1", line)<br />
'MBA'<br />
</python><br />
<br />
'''3.''' Egy file-ban ''soronként'' vannak a neptunkód--pontszám párok, ''szóközzel'' elválasztva. Írjunk python kódot, mely beolvassa ezt a file-t és egy ''szótárban'' tárolja a hallgatók eredményeit. A szótár kulcsai neptunkódok, az értékek ZH pontok.<br />
<br />
<python><br />
</python><br />
<br />
<python><br />
</python><br />
<br />
<python><br />
</python><br />
<br />
<python><br />
</python><br />
<br />
<python><br />
</python><br />
<br />
<python><br />
</python><br />
<br />
<python><br />
</python><br />
<br />
<python><br />
</python><br />
<br />
<python><br />
</python><br />
<br />
<python><br />
</python><br />
<br />
<python><br />
</python><br />
<br />
<python><br />
</python><br />
<br />
<python><br />
</python><br />
<br />
<python><br />
</python><br />
<br />
<python><br />
</python></div>
Wettl