-
Notifications
You must be signed in to change notification settings - Fork 16
Test branch #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ExperimentalHypothesis
wants to merge
2
commits into
master
Choose a base branch
from
test-branch
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Test branch #7
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| from random import randint as ri | ||
|
|
||
| def run(): | ||
| hidden_number = ri(1, 100) | ||
|
|
||
| while True: | ||
| try: | ||
| user_number = int(input("Guess the number: ")) | ||
| except ValueError as err: | ||
| print(f"Your input: {user_number} is not a real number. Try again") | ||
| continue | ||
|
|
||
| if user_number < hidden_number: | ||
| print("too small") | ||
| elif user_number > hidden_number: | ||
| print("too big") | ||
| else: | ||
| print("you won") | ||
| return | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| run() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| from random import choice | ||
|
|
||
| def collect_user_picks() -> set[int]: | ||
| print("Please pick 6 numbers. Each in range between 1-49\n") | ||
|
|
||
| picks = set() | ||
| count = 1 | ||
| while count != 7: | ||
| try: | ||
| pick = int(input(f"Please pick {count}. number: ")) | ||
| if not (1 <= pick <= 49): | ||
| print(f"Number {pick} has to be within 1-49 range, try again") | ||
| continue | ||
| if pick in picks: | ||
| print(f"Number {pick} can be picked only once, try again") | ||
| continue | ||
| except ValueError as e: | ||
| print("This is not a number, try again") | ||
| continue | ||
|
|
||
| count +=1 | ||
| picks.add(pick) | ||
|
|
||
| return picks | ||
|
|
||
|
|
||
| def get_winning_numbers() -> set[int]: | ||
| all_numbers = [i for i in range(1, 50)] | ||
| winning_numbers = {choice(all_numbers) for _ in range(6)} | ||
|
|
||
| return winning_numbers | ||
|
|
||
|
|
||
| def run(): | ||
|
|
||
| user_picks = collect_user_picks() | ||
| print(f"User picked: {sorted(user_picks)}") | ||
|
|
||
| winnig_numbers = get_winning_numbers() | ||
| print(f"Winning numbers are: {winnig_numbers}") | ||
|
|
||
| intersection = user_picks & winnig_numbers | ||
| print(f"user picked {len(intersection)} numbers that were in winning numbers.") | ||
|
|
||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| run() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # this problem is classical application of binary search algorithm but add some more complexity because of the user inputs | ||
| # here is the version without user inputs (user is automated) | ||
|
|
||
| from random import randint as ri | ||
|
|
||
| def binary_search(): | ||
| low, high = 1, 1000 | ||
| user_number = ri(1, 1000) | ||
| print(f"I am the user, and I am thinking of the number {user_number}") | ||
|
|
||
| while low <= high: | ||
| mid = (low + high) >> 1 | ||
|
|
||
| if user_number < mid: | ||
| print(f"You guessed {mid}, and it is too big") | ||
| high = mid - 1 | ||
| elif user_number > mid: | ||
| print(f"You guessed {mid}, and it is too small") | ||
| low = mid + 1 | ||
| else: | ||
| print(f"You guessed {mid}, and it is correct!") | ||
| return mid | ||
|
|
||
| if __name__ == "__main__": | ||
| binary_search() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # here is the version with the user inputs as asked in the course | ||
|
|
||
| def user_answer() -> str: | ||
| possible_answers = ["small", "big", "ok"] | ||
| while True: | ||
| answer = input() | ||
| if answer not in possible_answers: | ||
| print(f"You can answer only one of {possible_answers}") | ||
| continue | ||
| else: | ||
| return answer | ||
|
|
||
|
|
||
| def run(): | ||
| low, high = 1, 1000 | ||
| print(f"OK, I (the user) am thinking of number between {low} and {high} and you (the computer) must guess it") | ||
| print("After each guess I will give you answer, if your guess was too small or big\n'\n") | ||
|
|
||
| while low <= high: | ||
| mid = (low + high) >> 1 | ||
|
|
||
| print(f"I (the computer) am guessing {mid}. Is it small or big?") | ||
|
|
||
| answer = user_answer() | ||
| if answer == "big": | ||
| high = mid - 1 | ||
| elif answer == "small": | ||
| low = mid + 1 | ||
| else: | ||
| return mid | ||
|
|
||
| if __name__ == "__main__": | ||
| run() | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| nedelal jsem, je tam moc HTML |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import re | ||
| from random import randint as ri | ||
|
|
||
| def parse(code: str) -> tuple[str]: | ||
| pattern = re.compile(r'(\d*)D(3|4|6|8|10|12|20|100)([+-]\d+)?') | ||
| matched = pattern.match(code) | ||
|
|
||
| if matched: | ||
| rolls = int(matched.group(1)) if matched.group(1) else 1 | ||
| dice = int(matched.group(2)) | ||
| extras = int(matched.group(3)) if matched.group(3) else 0 | ||
|
|
||
| return rolls, dice, extras | ||
|
|
||
| raise ValueError(f"The code {code} is invalid") | ||
|
|
||
|
|
||
| def simulate(code: str) -> int: | ||
| try: | ||
| rolls, dice, extras = parse(code) | ||
| except ValueError as ex: | ||
| raise ValueError(f"The code '{code}' is invalid, simulation cannot continue.") from ex | ||
|
|
||
| result = extras | ||
| for _ in range(rolls): | ||
| result += ri(1, dice) | ||
|
|
||
| return result | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
|
|
||
| result = simulate("2D10+10") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| nedelal jsem nebyl cas |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as err je zbytečné, když s tím dále nepracuješ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm jo to tam nemusi byt no