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/Project_Default.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/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.

30 changes: 30 additions & 0 deletions 1] guessing game/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import random

def guess_the_number():

number_to_guess = random.randint(1, 100)

while True:

user_input = input("Guess the number: ")

try:
guess = int(user_input)
except ValueError:
print("It's not a number!")
continue


if guess < number_to_guess:
print("Too small!")
elif guess > number_to_guess:
print("Too big!")
else:
print("You win!")
break


guess_the_number()
print("Thanks for playing!")


45 changes: 45 additions & 0 deletions 2] loto/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import random


def get_user_numbers():
user_numbers = set()
while len(user_numbers) < 6:
try:

Choose a reason for hiding this comment

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

ten try muze byt klidne mensim podobe jako to mas v tom prvnim prikladu. Neni to chyba ale je to lepsi

user_input = input("Enter a number (1-49): ")
number = int(user_input)
if number < 1 or number > 49:

Choose a reason for hiding this comment

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

not 1 <= number <=49

print("Number must be between 1 and 49.")
elif number in user_numbers:
print("You have already entered this number.")
else:
user_numbers.add(number)
except ValueError:
print("That's not a valid number.")
return sorted(user_numbers)


def draw_lotto_numbers():
return sorted(random.sample(range(1, 50), 6))


def compare_numbers(user_numbers, lotto_numbers):
return len(set(user_numbers).intersection(set(lotto_numbers)))

Choose a reason for hiding this comment

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

tohle mi prijde nevhodne predelavat to tady na set abys mohl udelat intersetcion. Mnohem lepsi by bylo kdyzby ty funkce co ty data pripravuji uz set vratily



def main():
print("Welcome to the LOTTO Simulator!")
user_numbers = get_user_numbers()
print("\nYour numbers: ", user_numbers)

lotto_numbers = draw_lotto_numbers()
print("LOTTO draw: ", lotto_numbers)

matches = compare_numbers(user_numbers, lotto_numbers)
if matches >= 3:
print(f"Congratulations! You have matched {matches} number(s).")
else:
print("Unfortunately, you did not match enough numbers to win a prize.")


if __name__ == "__main__":
main()
36 changes: 36 additions & 0 deletions 3] guessing game 2/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
def computer_guess():
Copy link

@ExperimentalHypothesis ExperimentalHypothesis Feb 6, 2024

Choose a reason for hiding this comment

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

celkem zajimave reseni ktere asi funguje. Jen je pro mne trochu matouci jak to guess inicialiuzujes dvakrat, jednou pred tim while a pak uvnitr.

pak taky ta logika logika pricitani a odcitani tech attemps kdyz ho prictes ale kdyz to byl spatny feedback tak ho hned zas odectes v te else vetvi - trochu komplikovane a urcte by se to dalo jeste trochu poladit, ale celkove zatim asi jedno z nejlepsich reseni

Good job

print("Think of a number between 1 and 1000 and I'll guess it in no more than 10 moves.")
print("Respond with 'Too small', 'Too big', or 'You win' after each of my guesses.")

low = 1
high = 1000
guess = (low + high) // 2
feedback = ''
attempts = 0

while feedback != 'You win' and attempts < 10:
attempts += 1
print(f"My guess is: {guess}.")
feedback = input("Feedback: ").strip()

if feedback == 'Too small':
low = guess + 1
elif feedback == 'Too big':
high = guess - 1
elif feedback == 'You win':
print("Hooray! I guessed!") # Updated message
break
else:
print("Please enter a valid response ('Too small', 'Too big', 'You win').")
attempts -= 1 # Invalid feedback doesn't count as an attempt

guess = (low + high) // 2

if feedback != 'You win':
print("Seems like we've reached the max attempts or something went wrong. Did you cheat? 😉")


if __name__ == "__main__":
computer_guess()


52 changes: 52 additions & 0 deletions 4] guessing game 3/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from flask import Flask, request

app = Flask(__name__)

HTML = '''
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Guess My Number</title>
</head>
<body>
<h2>Is your number {{ guess }}?</h2>
<form action="/" method="post">
<input type="hidden" name="min" value="{{ min }}">
<input type="hidden" name="max" value="{{ max }}">
<input type="hidden" name="guess" value="{{ guess }}">
<button type="submit" name="answer" value="too_small">Too small</button>
<button type="submit" name="answer" value="too_big">Too big</button>
<button type="submit" name="answer" value="correct">You win</button>
</form>
</body>
</html>
'''


@app.route('/', methods=['GET', 'POST'])
def guess():
if request.method == 'POST':
min_val = int(request.form.get('min', 1))
max_val = int(request.form.get('max', 1000))
guess = int(request.form.get('guess', 500))
answer = request.form['answer']

if answer == 'too_small':
min_val = guess + 1
elif answer == 'too_big':
max_val = guess - 1
elif answer == 'correct':
return 'Congratulations! I guessed your number.'

guess = (min_val + max_val) // 2
else:
min_val = 1
max_val = 1000
guess = (min_val + max_val) // 2

return render_template_string(HTML, min=min_val, max=max_val, guess=guess)


if __name__ == '__main__':
app.run(debug=True)
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 roll_the_dice import roll_the_dice

def calculate_points(points):
"""Calculate points.

:param int points:

:rtype: int
:return: new_points
"""
roll = roll_the_dice("2D6")
if roll == 7:
points //= 7
elif roll == 11:
points *= 11
else:
points += roll
return points


def game_2001():
"""2001 game."""
user_points = 0
computer_points = 0

input("Press ENTER to roll the dice")
user_points += roll_the_dice("2D6")
computer_points += roll_the_dice("2D6")

while user_points < 2001 and computer_points < 2001:
print(f"User points: {user_points}\nComputer points: {computer_points}")
input("Press ENTER to roll the dice")
user_points = calculate_points(user_points)
computer_points = calculate_points(computer_points)

print(f"User points: {user_points}\n Computer points: {computer_points}")
if computer_points > user_points:
print("Computer wins!")
elif user_points > computer_points:
print("User wins!")
else:
print("Draw")


if __name__ == '__main__':
game_2001()

84 changes: 84 additions & 0 deletions 5] dice/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import random

POSSIBLE_DICE = (

"D100",

"D20",

"D12",

"D10",

"D8",

"D6",

"D4",

"D3"

)
def roll_the_dice(dice_code):
"""

Calculate dice roll from dice pattern.



:param str dice_code: dice pattern ex. `7D12-5`



:rtype: int, str

:return: dice roll value for proper dice pattern, `Wrong Input` text elsewhere

"""

Choose a reason for hiding this comment

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

tohle mas nejak divne naformatovane na to bacha. to skoro vypada jak kdyz si to odnekud zkopiroval a cely se ti to rozjelo. dost blbe se to mi to cte, tak to kdyztak pushni znovu s poradnym formtovanim

for dice in POSSIBLE_DICE:

if dice in dice_code:

try:

multiply, modifier = dice_code.split(dice)

except ValueError:

return "Wrong Input"

dice_value = int(dice[1:])

break

else:

return "Wrong Input"

try:

multiply = int(multiply) if multiply else 1

except ValueError:

return "Wrong Input"

try:

modifier = int(modifier) if modifier else 0

except ValueError:

return "Wrong Input"

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


if __name__ == '__main__':
print(roll_the_dice("2D10+10"))
print(roll_the_dice("D6"))
print(roll_the_dice("2D3"))
print(roll_the_dice("D12-1"))
print(roll_the_dice("DD34"))
print(roll_the_dice("4-3D6"))