Informatika2-2020/Gyak01

A MathWikiből
(Változatok közti eltérés)
a (Python futtatása)
18. sor: 18. sor:
 
  exit()
 
  exit()
  
== Own machine ==
+
== Saját gépről ==
Install [https://www.anaconda.com/distribution/ Anaconda], version '''3.7''' is needed!
+
Installáljuk az [https://www.anaconda.com/distribution/ Anaconda]-t, '''3.7'''-es verzió!
* [[AnacondaInstall|how to install Anaconda on windows]]
+
* [[AnacondaInstall|hogyan Installáljuk az Anacondat Windows-on]]
* You can use other distributions such as
+
* Más disztribúciót is lehet használni, úgymint:
 
** [https://www.python.org/downloads/ python.org]
 
** [https://www.python.org/downloads/ python.org]
 
** [https://winpython.github.io/ WinPython]
 
** [https://winpython.github.io/ WinPython]
  
Having Anaconda you can run several programs to interact with python:
+
Ha ezt megtettük, akkor több parancs segítségével is interakcióba léphetünk a Python-nal:
* command line: <tt>python</tt> or <tt>ipython</tt>
+
* parancssor: <tt>python</tt> vagy <tt>ipython</tt>
 
* Spyder
 
* Spyder
 
* <tt>idle</tt>
 
* <tt>idle</tt>
 
* <tt>jupyter notebook</tt>
 
* <tt>jupyter notebook</tt>
  
= Exercises =
+
= Feladatok =
== Introduction ==
+
== Bevezetés ==
* Try the notebook from the lecture.
+
* Próbáljuk ki az előadás notebook-ot
** download from wiki and upload it into jupyter.math.bme.hu
+
** le kell töltni a wiki-ről és feltölteni a jupyter.math.bme.hu-ra
* Try a welcoming program (from terminal)!
+
* Próbáljuk megírni az illedelmes köszönő programot (terminálból is)!
* Try division (integer and float)
+
* Próbáljuk ki az osztást (integer és float)
  
== tocelsius ==
+
== celsiusra ==
Write a python function that convets from Fahrenheit to Celsius
+
  
The function should
+
Írjunk python függvényt, ami egy Fahrenheitben megkapott h&#337;mérsékletet átvált Celsius fokra.
* be called <tt>tocelsius</tt>
+
A függvény neve legyen <b>celsiusra</b>, és paraméterként egy <b>fahrenheit</b> nev&#369; számot kapjon.
* have one parameter (called <tt>fahrenheit</tt>)
+
Úgy lehet kiszámolni ezt az értéket, hogy a Fahrenheit-ben mért h&#337;mérsékletb&#337;l kivonunk 32-t, majd az így kapott számot megszorozzuk 5/9-el.
* return the appropriate Fahrenheit degrees as float.
+
 
* To get the Celsius, subtract <math>32</math> from the Fahrenheit value then multipy with <math>5/9</math>.
+
* https://hu.wikipedia.org/wiki/Fahrenheit
* See [https://www.metric-conversions.org/temperature/fahrenheit-to-celsius.htm examples here]
+
* [https://www.metric-conversions.org/temperature/fahrenheit-to-celsius.htm példák itt]
  
 
== isaprime ==
 
== isaprime ==

A lap 2020. február 12., 11:41-kori változata

előző fel következő

Tartalomjegyzék

Python futtatása

Jupyterhub

  • Jelentkezzetek be a jupyter.math.bme.hu-ra a leibniz-es felhasználónévvel és jelszóval
  • Python 3-at fogunk használni!
  • Ez a notebook hasonlít ahhoz, mint amikor saját gépről ezt futtatod:
jupyter notebook

leibniz

  • A konzol-ba ezt írjuk be:
python3
  • kilépni az így lehet:
exit()

Saját gépről

Installáljuk az Anaconda-t, 3.7-es verzió!

Ha ezt megtettük, akkor több parancs segítségével is interakcióba léphetünk a Python-nal:

  • parancssor: python vagy ipython
  • Spyder
  • idle
  • jupyter notebook

Feladatok

Bevezetés

  • Próbáljuk ki az előadás notebook-ot
    • le kell töltni a wiki-ről és feltölteni a jupyter.math.bme.hu-ra
  • Próbáljuk megírni az illedelmes köszönő programot (terminálból is)!
  • Próbáljuk ki az osztást (integer és float)

celsiusra

Írjunk python függvényt, ami egy Fahrenheitben megkapott hőmérsékletet átvált Celsius fokra. A függvény neve legyen celsiusra, és paraméterként egy fahrenheit nevű számot kapjon. Úgy lehet kiszámolni ezt az értéket, hogy a Fahrenheit-ben mért hőmérsékletből kivonunk 32-t, majd az így kapott számot megszorozzuk 5/9-el.

isaprime

Write a function that tells whether a number is a prime or not!

The function should be called isaprime and have one parameter:

  • x, the number in question

The function should return True or False depending on the number.

For safety reasons, you can check the type and value of the input. Accept only positive integers! If you get a non-integer or a non-positive integer, return None

roomtemp

According to <a href="https://en.wikipedia.org/wiki/Room_temperature">Wikipedia</a> a room has a temperature between 18°C and 25°C. Write a function that decides that for us.

The function should

  • be called roomtemp
  • have one parameter: degree the temperature of the room in Celsius degrees.
  • return either one of the following strings depending on the temperature:
    • "Too cold!"
    • "Too hot!"
    • "OK"

Mind that there is a difference between print and return

factorial

Write a function which calculates n factorial

factorial

Write a function which calculates n factorial

without 2

You should divide a positive integer n with a power of two, until it is not divisible by 2.

Call the function withouttwo with one parameter:

  • n, a positive integer
  • Return the number divided by the greatest possible power of two.

For example

1 -> 1
2 -> 1
3 -> 3
4 -> 1
6 -> 3
7 -> 7
9 -> 9
10 -> 5
100 -> 25

előző fel következő

Személyes eszközök