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
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/workshop.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions 1] guessing game/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from random import randint
number = randint(1, 100)
win = False

Choose a reason for hiding this comment

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

ten kod by mel byt zabaleny do funcki.

while win == False:
#system generates a number in range 1-100 and user tries to guess it
#system provides clues Too small/too big and validates whether input is a number
try:
user_input = int(input("Guess a number between 1 and 100: "))
if user_input < number:
print("Too small")
elif user_input > number:
print("Too big")
else:
print("You win!")
win = True
except ValueError:
print("It's not a number!")
35 changes: 35 additions & 0 deletions 2] loto/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from random import randint

Choose a reason for hiding this comment

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

zase ten kod by mel byt zalbaleny do funcki


user_input=[]
drawn_numbers=[]
matched=0
#system collects 6 different numbers in given range and sorts them
for x in range(6):
while True:

Choose a reason for hiding this comment

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

tady delas dvijity loop proc? to je zbytecne

try:
number = int(input(f"Input {x+1}. number in range 1-49: "))
if number not in user_input and number in range(1,49):
user_input.append(number)
break
else:
print("Every number can be picked just once and must be in given range!")
except ValueError:
print("Input is not a number")
user_input.sort()
print(user_input)

#system draws 6 random numbers and sorts them
for x in range(6):
while True:

Choose a reason for hiding this comment

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

taky dvojity loop uplne zbytecne. jdi na to vic primocare

number = randint(1,49)
if number not in drawn_numbers:
drawn_numbers.append(number)
break
drawn_numbers.sort()
print(drawn_numbers)

#system checks whether there are some matches in user input and system draws
for x in range(6):
if user_input[x] in drawn_numbers:
matched +=1
print(f'You matched {matched} number(s)')
30 changes: 30 additions & 0 deletions 3] guessing game 2/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
print("Think about a number from 0 to 1000 and let me guess it!")

answer = ""
min = 0
max = 1000
count = 0

#the cycle continues till the guess is correct
while answer != "3":

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.

flor div // je lepsi


#If the count of guesses reaches 10, user must be cheating, therefore system calls him liar
#Otherwise system cointinues guessing
if count == 10:

Choose a reason for hiding this comment

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

toto neni vubec potreba kontrolovat

print("Liar liar pants on fire!")
break
else:
print(f"Guessing: {guess}")
count += 1

#user inputs a number to give a clue to the system
answer = input("Your verdict 1 - Too small, 2 - Too big, 3 - You win => ")
Copy link

@ExperimentalHypothesis ExperimentalHypothesis Feb 3, 2024

Choose a reason for hiding this comment

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

neni osetrena vyjimka kdyz nekdo zada neco jineho nez 3 nebo 2.

Vlastne to skace vzdy do else vetve kdyz clovek zada neco jineho, takze tahle logika neni spravne


if answer == "3":
print("I won! Thanks for game")
elif answer == "2":
max = guess
else:
min = guess
36 changes: 36 additions & 0 deletions 4] guessing game 3/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from flask import Flask, render_template, request

app = Flask(__name__, template_folder='templates')

@app.route('/', methods=['GET', 'POST'])
def guess_number():
min_num = 0
max_num = 1000
count = 0

#Flask post method that handles flow of values
if request.method == 'POST':
min_num = int(request.form.get('min'))
max_num = int(request.form.get('max'))
count = int(request.form.get('count'))
answer = request.form['answer']
count += 1

# If the count of guesses reaches 10, user must be cheating, therefore system calls him liar
if count == 10:
return "Liar liar pants on fire!"

if answer == "3":
return "I won! Thanks for game"
elif answer == "2":
max_num = int((max_num - min_num) / 2) + min_num
else:
min_num = int((max_num - min_num) / 2) + min_num
#counting number to guess
guess = int((max_num - min_num) / 2) + min_num

#template and variable handling
return render_template('guess.html', min=min_num, max=max_num, count=count, guess=guess)

if __name__ == '__main__':
app.run(debug=True)
33 changes: 33 additions & 0 deletions 4] guessing game 3/templates/guess.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Number Guessing Game</title>
</head>
<body>
<h1>Number Guessing Game</h1>
<p>Think about a number from 0 to 1000 and let me guess it!</p>
<p>Guessing: {{ guess }}</p>
<form method="POST">
<input type="hidden" name="min" value="{{ min }}">
<input type="hidden" name="max" value="{{ max }}">
<input type="hidden" name="count" value="{{ count }}">
<input type="hidden" name="answer" value="2">
<input type="submit" value="Too big">
</form>
<form method="POST">
<input type="hidden" name="min" value="{{ min }}">
<input type="hidden" name="max" value="{{ max }}">
<input type="hidden" name="count" value="{{ count }}">
<input type="hidden" name="answer" value="1">
<input type="submit" value="Too small">
</form>
<form method="POST">
<input type="hidden" name="min" value="{{ min }}">
<input type="hidden" name="max" value="{{ max }}">
<input type="hidden" name="count" value="{{ count }}">
<input type="hidden" name="answer" value="3">
<input type="submit" value="You win">
</form>
</body>
</html>
22 changes: 22 additions & 0 deletions 5] dice/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import re
import random
#using regex and random to simulate the dice throw
def roll_dice(dice_code):
pattern = r'(\d*)D(\d+)([-+]\d+)?'

Choose a reason for hiding this comment

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

tenhle pattern neni spravne. umozni to napsat treba D7 coz je zakazno

match = re.match(pattern, dice_code)

try:
num_rolls = int(match.group(1)) if match.group(1) else 1
dice_type = int(match.group(2))
modifier = int(match.group(3)) if match.group(3) else 0
result = sum(random.randint(1, dice_type) for _ in range(num_rolls)) + modifier

Choose a reason for hiding this comment

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

wau!!

tohle je celkem optimalni resesni, skoda ze nemas dobre ten pattern.

return result
except AttributeError:
return "Invalid dice"


print(roll_dice("2D10+10"))
print(roll_dice("D6"))
print(roll_dice("2D3"))
print(roll_dice("D12-1"))
print(roll_dice("XD1"))