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
29 changes: 29 additions & 0 deletions 1] guessing game/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from random import randint


def guess_num():
"""
guess_num function take number from user input
then compare it with chosen random number 1-100
and react in proper way for tip <, > or ==
"""
x = input("Guess the number:")
try:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ten try block je zytecne velkej, staci vylozene try na tu oblast kde tu vyjimku cekas.

x = int(x)
if x < number:
print("Too small!")
return guess_num()
elif x > number:
print("Too big!")
return guess_num()
elif x == number:
print("You win!")
except ValueError:
print("It's not a number!")
return guess_num()


number = randint(1, 100)

if __name__ == '__main__':
guess_num()
52 changes: 52 additions & 0 deletions 2] loto/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from random import choice


def player_tip():
"""
player_tip function ask player for 6 numbers from 1 to 49
with validation for range, repetition and value
"""
tip_list = []

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toto by melo byt jako set, ne jako list, protoze tam budes delat membership test a ten na setu funguje lepe

while len(tip_list) < 6:
try:
x = (int(input("Choose number from 1 to 49:\n")))
if x not in tip_list and x in range(1, 50):
tip_list.append(x)
else:
print("Please choose different number")
except ValueError:
print("Invalid number, try again")
return sorted(tip_list)


def computer_tip():
"""
computer_tip function draw 6 different numbers from 1 to 49
"""
range_list = list(range(1, 50))
c_tip_list = []

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zase je lepsi set

while len(c_tip_list) < 6:
y = choice(range_list)
c_tip_list.append(y)
range_list.remove(y)
return sorted(c_tip_list)


def lotto():
"""
lotto collects player_tip and computer_tip results and count
similar tips
"""
player_list = player_tip()
computer_list = computer_tip()
matched = 0
for tip in player_list:
if tip in computer_list:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tady prave delas ty mebership testy..

matched += 1
print(f"Player tips :\n {player_list}")
print(f"Computer tips :\n {computer_list}")
print(f"You guessed {matched} number/s")


if __name__ == '__main__':
lotto()
32 changes: 32 additions & 0 deletions 3] guessing game 2/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
def guessing_from_player():
"""
guessing_from_player program ask player to think number from 0 to 1000
then asking for value and react if too low, too high, or you guessed entered
if not guessed in 10 round, player is cheating
:return:
"""
print("""Think about a number from 0 to 1000, and let me guess it!
Press any key when you are ready""")
input()
round = 0
min = 0
max = 1000
while round < 10:
guess = int((max - min) / 2) + min

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

necastuj, ale udelej //

print(f"Guessing: {guess}")
answer = input("Enter too low, too high or you guessed:\n").lower()
if answer == "you guessed":
return print("I won!")
elif answer == "too high":
max = guess
round += 1
elif answer == "too low":
min = guess
round += 1
else:
print("Please enter only too low, too high or you guessed")
print("Don't cheat!")


if __name__ == '__main__':
guessing_from_player()
48 changes: 48 additions & 0 deletions 4] guessing game 3/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from flask import Flask, request, render_template
app = Flask(__name__)

def calc():
"""
calc function takes min and max from web form, calculate and return guess
:return:
"""
min = int(request.form['min'])
max = int(request.form['max'])
guess = ((max - min) // 2) + min
return guess
@app.route("/", methods=['GET', 'POST'])
def guessing_from_player():
"""
guessing_from_player program /w flask ask player to think a number from 0 to 1000
reacting to POST returned value and calculate new guess
:return:
"""
if request.method == "POST":
answer = request.form['guess_button']
round = int(request.form['round'])
if round == 10:
return render_template("cheater.html")
if answer == "you guessed":
return render_template("win.html")
elif answer == "too high":
max = calc()
min = int(request.form['min'])
guess = ((max - min) // 2) + min
round += 1
return render_template("index.html", guess=guess, min=min, max=max, round=round)
elif answer == "too low":
min = calc()
max = int(request.form['max'])
guess = ((max - min) // 2) + min
round += 1
return render_template("index.html", guess=guess, min=min, max=max, round=round)
else:
min = 0
max = 1000
round = 1
guess = ((max - min) // 2) + min
return render_template("index.html", guess=guess, min=min, max=max, round=round)


if __name__ == '__main__':
app.run(debug=True)
Binary file added 4] guessing game 3/static/cheater.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 4] guessing game 3/static/win.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions 4] guessing game 3/templates/cheater.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Cheater</title>
</head>
<body>
<p>You are cheater!</p>
<img src="{{ url_for('static', filename='cheater.jpg') }}" class="image" alt="You really disappointed me..." width="500" height="500">
</body>
</html>
20 changes: 20 additions & 0 deletions 4] guessing game 3/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Guessing game</title>
</head>
<body>
<p>Think about a number from 0 to 1000, and let me guess it!</p>
<p>My tip is : {{guess}}</p>
<form action="/" method="POST">
<button type="submit" name="guess_button" value="too low">too low</button>
<button type="submit" name="guess_button" value="too high">too high</button>
<button type="submit" name="guess_button" value="you guessed">you guessed</button>
<input type="hidden" id="min" name="min" value={{min}}>
<input type="hidden" id="max" name="max" value={{max}}>
<input type="hidden" id="round" name="round" value={{round}}>
</form>

</body>
</html>
14 changes: 14 additions & 0 deletions 4] guessing game 3/templates/win.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Computers epic win</title>
</head>
<body>
<p>I WON</p>
<p>I WON</p>
<p>I WON</p>
<img src="{{ url_for('static', filename='win.jpg') }}" class="image" alt="I won" width="1000" height="700">

</body>
</html>
47 changes: 47 additions & 0 deletions 5] 2001/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from random import randint


def game():
"""
game is 2001 game with throwing 2 D6 dices, adding throw value to score.
From second turn if roll is 7 then divide score by 7, if 11, multiply score by 11.
First player who hit or exceeded 2001 wins
:return:
"""
player1_points = 0
player2_points = 0
turn = 0
while player1_points < 2001 and player2_points < 2001:
input("Press enter to throw")
turn += 1
player1 = d6_throw()
player2 = d6_throw()
if turn >= 2 and player1 == 7:
player1_points = player1_points // 7
elif turn >= 2 and player1 == 11:
player1_points = player1_points * 11
else:
player1_points += player1

if turn >= 2 and player2 == 7:
player2_points = player2_points // 7
elif turn >= 2 and player2 == 11:
player2_points = player1_points * 11
else:
player2_points += player2
print(f"Player points : {player1_points}")
print(f"Computer points : {player2_points}")
if player1_points >= 2001:
return("Player WIN!")
elif player2_points >= 2001:
return ("Computer WIN!")


def d6_throw():
"""
d6_throw represents 2 throws of D6 dices
:return:
"""
return randint(1, 6) + randint(1, 6)

print(game())
75 changes: 75 additions & 0 deletions 5] 2001/mod1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
from random import randint, choice

dices = ("D3", "D4", "D6", "D8", "D10", "D12", "D20", "D100")


def dice_throw():
"""
dice_throw function takes input from user, confirming existing dice.
After that simulate throw of dice. 2 choices of dice and throws in total.
:return:
"""
result = 0
throw = 0
while throw < 2:
for take in range(2):
command = input("Enter dice code D3, D4, D6, D8, D10, D12, D20 or D100:\n")
if command not in dices:
print("Wrong input")
else:
dice = int(command.removeprefix("D"))
result += randint(1, dice)
throw += 1
return result


def comp_dice_throw():
"""
comp_dice_throw simulates random choice of 2 dices and throw
:return:
"""
result = 0
for take in range(2):
command = choice(dices)
dice = int(command.removeprefix("D"))
result += randint(1, dice)
return result


def game():
"""
game is 2001 game with throwing 2 D6 dices, adding throw value to score.
From second turn if roll is 7 then divide score by 7, if 11, multiply score by 11.
First player who hit or exceeded 2001 wins
:return:
"""
player1_points = 0
player2_points = 0
turn = 0
while player1_points < 2001 and player2_points < 2001:
turn += 1
player1 = dice_throw()
player2 = comp_dice_throw()
if turn >= 2 and player1 == 7:
player1_points = player1_points // 7
elif turn >= 2 and player1 == 11:
player1_points = player1_points * 11
else:
player1_points += player1

if turn >= 2 and player2 == 7:
player2_points = player2_points // 7
elif turn >= 2 and player2 == 11:
player2_points = player1_points * 11
else:
player2_points += player2
print(f"Player points : {player1_points}")
print(f"Computer points : {player2_points}")
if player1_points >= 2001:
return "Player WIN!"
elif player2_points >= 2001:
return "Computer WIN!"


if __name__ == '__main__':
print(game())
39 changes: 39 additions & 0 deletions 5] dice/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from random import randint
import re

dices = ("3", "4", "6", "8", "10", "12", "20", "100")
dice_pattern = re.compile(r"^(\d*)D(\d+)([+-]\d+)?$")


def dice_throw():
"""
dice_throw function takes input from user, confirming dice_pattern.
Divide entry to multiply, modifier and dice, then calculate random throws and return value.
:return:
"""
command = input("Enter dice code:\n")
match = dice_pattern.search(command)
if not match:
return "Wrong input"

multiply, dice, modifier = match.groups()
if dice not in dices:
return "Wrong input"

if multiply:
multiply = int(multiply)
else:
multiply = 1

if modifier:
modifier = int(modifier)
else:
modifier = 0

dice = int(dice)

return sum([randint(1, dice) for _ in range(multiply)]) + modifier


if __name__ == '__main__':
print(dice_throw())
1 change: 1 addition & 0 deletions test2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("Hi there, its working now?")