diff --git a/01.py b/01.py index 1b12745..3e86a1b 100644 --- a/01.py +++ b/01.py @@ -4,14 +4,14 @@ # Format output # https://docs.python.org/3/library/string.html#formatspec -print ("My name is {1} and I am {0} years old.".format(41, "Stepan")) +print("My name is {1} and I am {0} years old.".format(41, "Stepan")) # Exercise # 1. Change text inside "" # 2. Try to use ' instead of " # 3. Try to print more lines of text # 4. Try to put " inside "" -# 5. Try print (1+1) -# 6. Try print ("My name is " + "Stepan")? -# 7. Try print ("Hello" * 5) -# 8. Try add more items to 'format' function \ No newline at end of file +# 5. Try print(1+1) +# 6. Try print("My name is " + "Stepan")? +# 7. Try print("Hello" * 5) +# 8. Try add more items to 'format' function diff --git a/02.py b/02.py index 2de2082..14669ff 100644 --- a/02.py +++ b/02.py @@ -2,20 +2,20 @@ colors = ["pink", "blue", "red", "green"] # Print 2nd item in array -print (colors[1]) +print(colors[1]) # Variable color = 2 # Print variable value -print (color) +print(color) # Print 3rd item in array -print (colors[color]) +print(colors[color]) # Add new item to first position colors.insert(0, "orange") # Print 3rd item in array # https://docs.python.org/3/library/string.html#formatspec -print ("1st color is {0} and 2nd is {1}".format(colors[0], colors[1])) +print(f"1st color is {colors[0]} and 2nd is {colors[1]}") # Reverse item order in array colors.reverse() diff --git a/03.py b/03.py index 8e85d54..9fc2d5d 100644 --- a/03.py +++ b/03.py @@ -3,12 +3,12 @@ # Let's try if the code will work try: - print (colors[1]) + print(colors[1]) # Print non-existing item in array - print (colors[1000]) + print(colors[1000]) # If not show error message except: - print ("ERROR: item doesn't exist!") + print("ERROR: item doesn't exist!") print("I am still running.") # Exercise diff --git a/05.py b/05.py index e88d59b..5c379a8 100644 --- a/05.py +++ b/05.py @@ -7,12 +7,12 @@ # first index is rows # second index is column -print (colors[2][1]) +print(colors[2][1]) # Print all colors in list # {1:X} prints number in hexadecimal format for color in colors: - print ("Color {0} is in decimal {1} and hexadecimal 0x{1:06X}.".format(color[0], color[1])) + print(f"Color {0} is in decimal {1} and hexadecimal 0x{color[1]:06X}.") # Exercise # 1. Create the following output, try two ways (special characters, nested loops) diff --git a/06.py b/06.py index 168e9bb..c2aec46 100644 --- a/06.py +++ b/06.py @@ -22,7 +22,7 @@ for color in colors: # Check if color is my favorite one if color[0] == favorite: - print ("I like 0x{0:06X}".format(color[1])) + print(f"I like 0x{color[1]:06X}") # Exercise # 1. If the color is not your favorite print a message like this (if-else statement): diff --git a/07.py b/07.py index 80c1f76..24ca719 100644 --- a/07.py +++ b/07.py @@ -1,11 +1,11 @@ def hi(): - print ("Hi there!") + print("Hi there!") hi() def printColor(c): # return statement returns value - return "{0}: 0x{1:06x}".format(c[0], c[1]) + return f"{c[0]}: 0x{c[1]:06x}" # Array (list) of colors colors = [["pink", 0xFF1493], @@ -16,7 +16,7 @@ def printColor(c): for color in colors: # printColor returns a string value message = printColor(color) - print (message) + print(message) # Exercise # 1. Try to move the function to the end of the code diff --git a/08.py b/08.py index 414245f..8c11969 100644 --- a/08.py +++ b/08.py @@ -1,10 +1,14 @@ # Import libraries -# https://docs.python.org/3/library/time.html -import time -# https://docs.python.org/3/library/math.html -import math +import time # https://docs.python.org/3/library/time.html +import math # https://docs.python.org/3/library/math.html + # Print local time -print (time.strftime("%d.%m.%Y %H:%M:%S", time.localtime())) +print(time.strftime("%d.%m.%Y %H:%M:%S", time.localtime())) +# https://stackoverflow.com/questions/9525944/python-datetime-formatting-without-zero-padding +#print(time.strftime("%-d.%-m.%Y %H:%M:%S", time.localtime())) # only on GNU/Linux +# https://stackoverflow.com/a/9526118/2556118 +#print(time.localtime()) +print("{d.tm_mday}.{d.tm_mon}.{d.tm_year} {d.tm_hour}:{d.tm_min:02}:{d.tm_sec:02}".format(d=time.localtime())) # Pythagorean theorem # https://en.wikipedia.org/wiki/Pythagorean_theorem @@ -19,4 +23,4 @@ def calculateHypotenuse(a, b): # Excercise # 1. Try to move the import statement after the print function -# 2. Import urllib2 and download content of any website \ No newline at end of file +# 2. Import urllib2 and download content of any website diff --git a/README.md b/README.md index 9b9f5d3..28e7bbd 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,19 @@ # Python training for Czechitas ## Download and install Python -In order to download Python go to [official python site] (https://www.python.org/downloads/) and select "Download Python 3.5.0". +In order to download Python go to [official python site] (https://www.python.org/downloads/) and select "Download Python 3.11". -IMPORTANT note for Windows users: when installing, do not forget to select "Add python 3.5 to PATH" option. +IMPORTANT note for Windows users: when installing, do not forget to select "Add python 3.11 to PATH" option. ## Download and install Visual Studio Code [Visual Studio Code] (https://code.visualstudio.com/) is simple multiplatform editor for developers. +Alternatively you can download the [(g)Vim](https://www.vim.org/) editor. -## Azure -If you want to try to create website activate [Azure Free Trial] (https://azure.microsoft.com/en-us/pricing/free-trial/) or Azure for students on [Dreamspark] (https://www.dreamspark.com/). +## Cloud +If you want to try to create website +get start for free with [Google Cloud Platform](https://cloud.google.com/free) +or activate [Azure Free Trial] (https://azure.microsoft.com/en-us/pricing/free-trial/) +or Azure for students on [Dreamspark] (https://www.dreamspark.com/). ## Where to learn more @@ -20,4 +24,4 @@ If you want to try to create website activate [Azure Free Trial] (https://azure. ### Trainings [edX] (https://www.edx.org/course?search_query=python) [coursera] (https://www.coursera.org/courses?query=python) -[codeacademy] (https://www.codecademy.com/learn/python) \ No newline at end of file +[codeacademy] (https://www.codecademy.com/learn/python) diff --git a/game/magic_ball.py b/game/magic_ball.py index 40b12b2..d5ce36d 100644 --- a/game/magic_ball.py +++ b/game/magic_ball.py @@ -12,15 +12,15 @@ "Reply hazy, try again", "Ask again later", "Better not tell you now", "Cannot predict now", "Dont count on it", "My reply is no", "My sources say no", "Outlook not so good", "Very doubtful"] -print ('Welcome to Magic 8 Ball!') -print ('Please ask your question!') +print('Welcome to Magic 8 Ball!') +print('Please ask your question!') question = input() play = True while play == True: what = random.choice(answers) - print ('My answer is: '+ what +'!') - print ('If you want to exit, type quit or ask again!') + print('My answer is: '+ what +'!') + print('If you want to exit, type quit or ask again!') question = input() if question == 'quit': quit = sys.exit("Good bye!") diff --git a/hints.py b/hints.py index 65bc6a1..72e3725 100644 --- a/hints.py +++ b/hints.py @@ -1,36 +1,36 @@ # 02.py ---------------------------------------------- colors = ["pink", "blue", "red", "green"] # number of items -print (len(colors)) +print(len(colors)) # add new item at the end of array colors.append("black") -print (colors) +print(colors) # 04.py ---------------------------------------------- colors = ["pink", "blue", "red", "green"] for color in reversed(colors): - print (color) + print(color) # 05.py ---------------------------------------------- colors = [["pink", 0xFF1493], ["blue", 0x0000FF], ["red", 0xFF0000], ["green", 0x00FF00]] # 1st solution for color in colors: - print ("{0}\r\n{1:x}".format(color[0], color[1])) + print(f"{color[0]}\r\n{color[1]:x}") # 2nd solution for color in colors: for parts in color: - print (parts) + print(parts) # reading from file -print ("Reading from file") +print("Reading from file") with open('colors.txt') as f: colors = f.readlines() -print (colors) +print(colors) # 06.py ---------------------------------------------- @@ -38,20 +38,20 @@ for color in colors: # Check if color is my fovorite one if color[0] == favorite: - print ("I like x:{0:x}".format(color[1])) + print(f"I like x:{color[1]:x}") else: - print ("Don't like {0} color".format(color[0])) + print(f"Don't like {color[0]} color") # 07.py ---------------------------------------------- def printColor(c, n): - return "{0}:x:{1:x}".format(c, n) + return "{sc0}:x:{n:x}" # Array (list) of colors colors = [["pink", 0xFF1493], ["blue", 0x0000FF], ["red", 0xFF0000], ["green", 0x00FF00]] for color in colors: - print (printColor(color[0], color[1])) + print(printColor(color[0], color[1])) # 08.py ---------------------------------------------- import urllib.request @@ -63,4 +63,4 @@ def printColor(c, n): exit() content = resp.read() -print (content) +print(content) diff --git a/intenzivni_kurz/python_kurz_4_1.py b/intenzivni_kurz/python_kurz_4_1.py index b27b705..2e6398e 100644 --- a/intenzivni_kurz/python_kurz_4_1.py +++ b/intenzivni_kurz/python_kurz_4_1.py @@ -26,9 +26,9 @@ def string_upper_lower(s): upper +=1 if c.islower(): lower +=1 - print ("Řetězec: ", s) - print ("Počet velkých písmen: ", upper) - print ("Počet malých písmen: ", lower) + print("Řetězec: ", s) + print("Počet velkých písmen: ", upper) + print("Počet malých písmen: ", lower) s = """Byl jeden Řek a ten mi řek, abych mu řek, kolik je v Řecku řeckých řek a já mu řek, diff --git a/intenzivni_kurz/python_kurz_4_2.py b/intenzivni_kurz/python_kurz_4_2.py index ca803b9..a3879d7 100644 --- a/intenzivni_kurz/python_kurz_4_2.py +++ b/intenzivni_kurz/python_kurz_4_2.py @@ -17,8 +17,8 @@ def meal_vouchers(lunch_price, meal_voucher_value): meal_voucher_number = int(lunch_price) // int(meal_voucher_value) money = int(lunch_price) - (meal_voucher_number * int(meal_voucher_value)) - print ('Oběd stojí:', lunch_price, 'Kč') - print ('Zaplaťte hotově:', money, 'Kč') - print ('Zaplaťte stravenkami:', meal_voucher_number, 'ks po', meal_voucher_value, 'Kč') + print('Oběd stojí:', lunch_price, 'Kč') + print('Zaplaťte hotově:', money, 'Kč') + print('Zaplaťte stravenkami:', meal_voucher_number, 'ks po', meal_voucher_value, 'Kč') meal_vouchers(500, 74) \ No newline at end of file diff --git a/python_workshop_cz.ipynb b/python_workshop_cz.ipynb index f8edc7d..be39a97 100644 --- a/python_workshop_cz.ipynb +++ b/python_workshop_cz.ipynb @@ -1001,7 +1001,7 @@ "source": [ "name = \"Eliška\"\n", "number = 42\n", - "print(\"Jmenuji se {0} a mám ráda číslo {1}.\".format(name, number))" + "print(f\"Jmenuji se {name} a mám ráda číslo {number}.\")" ] }, { @@ -1407,7 +1407,7 @@ ], "source": [ "first = 1\n", - "print (\"první barva je\", colors_list[first])" + "print(\"první barva je\", colors_list[first])" ] }, { diff --git a/website/index.py b/website/index.py index 3224b5f..deac7c9 100644 --- a/website/index.py +++ b/website/index.py @@ -28,10 +28,10 @@ def application(environ, start_response): # convert response from JSON to array of dictionaries rates = json.loads(content) - # imagine yield as print (very, very simple imagination) + # imagine yield as print(very, very simple imagination) # https://docs.python.org/2/reference/simple_stmts.html#the-yield-statement yield '

CSAS Exchange Rates

' yield '\r\n' for rate in rates: - yield "\r\n".format(rate['shortName'], rate['currBuy'], rate['currSell']) - yield '
{0}{1}{2}
\r\n' \ No newline at end of file + yield f"{rate['shortName']}{rate['currBuy']}{rate['currSell']}\r\n" + yield '\r\n'