Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions 01.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# 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
8 changes: 4 additions & 4 deletions 02.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions 03.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions 05.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion 06.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions 07.py
Original file line number Diff line number Diff line change
@@ -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],
Expand All @@ -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
Expand Down
16 changes: 10 additions & 6 deletions 08.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
# 2. Import urllib2 and download content of any website
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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)
[codeacademy] (https://www.codecademy.com/learn/python)
8 changes: 4 additions & 4 deletions game/magic_ball.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
Expand Down
24 changes: 12 additions & 12 deletions hints.py
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
# 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 ----------------------------------------------
favorite = "blue"
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
Expand All @@ -63,4 +63,4 @@ def printColor(c, n):
exit()

content = resp.read()
print (content)
print(content)
6 changes: 3 additions & 3 deletions intenzivni_kurz/python_kurz_4_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions intenzivni_kurz/python_kurz_4_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions python_workshop_cz.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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}.\")"
]
},
{
Expand Down Expand Up @@ -1407,7 +1407,7 @@
],
"source": [
"first = 1\n",
"print (\"první barva je\", colors_list[first])"
"print(\"první barva je\", colors_list[first])"
]
},
{
Expand Down
6 changes: 3 additions & 3 deletions website/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<h1>CSAS Exchange Rates</h1>'
yield '<table>\r\n'
for rate in rates:
yield "<tr><td>{0}</td><td align='right'>{1}</td><td align='right'>{2}</td></tr>\r\n".format(rate['shortName'], rate['currBuy'], rate['currSell'])
yield '</table>\r\n'
yield f"<tr><td>{rate['shortName']}</td><td align='right'>{rate['currBuy']}</td><td align='right'>{rate['currSell']}</td></tr>\r\n"
yield '</table>\r\n'