Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Cursed Expressions Generator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Cedric Hartz
Cursed Expressions Generator
Commits
9bce19f5
There was an error fetching the commit references. Please try again later.
Commit
9bce19f5
authored
Nov 15, 2022
by
Cedric Hartz
Browse files
Options
Downloads
Patches
Plain Diff
WEIGHTS hinzugefügt; Wahrscheinlichkeiten etc leicht angepasst
parent
1eeb551c
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
cursed_generator.py
+7
-4
7 additions, 4 deletions
cursed_generator.py
with
7 additions
and
4 deletions
cursed_generator.py
+
7
−
4
View file @
9bce19f5
...
...
@@ -4,7 +4,6 @@
"""
TODO:
- bitweise Operationen
- eventuell weights für die OPERATORS
- Erklärung:
- binary operators
...
...
@@ -17,10 +16,12 @@ OPERATORS = ("**", "%", "*", "//", "/", "+", "-", ">=", "<=", ">", "<", "==", "!
EQUALITY_OPERATORS
=
(
"
<
"
,
"
>
"
,
"
<=
"
,
"
>=
"
,
"
==
"
,
"
!=
"
,
"
is
"
,
"
is not
"
)
# these follow a different precedence rule (1<2<3 <=> 1<2 and 2<3)
PRECEDENCE
=
({
"
**
"
},
{
"
%
"
,
"
*
"
,
"
//
"
,
"
/
"
},
{
"
+
"
,
"
-
"
},
EQUALITY_OPERATORS
,
{
"
not
"
},
{
"
and
"
},
{
"
or
"
})
# precedence order
### Probabilities:
WEIGHTS
=
(
10
,
6
,
10
,
7
,
10
,
10
,
10
,
8
,
8
,
8
,
8
,
10
,
10
,
10
,
10
,
8
,
10
,
10
)
# not has own probability P_NOT
assert
len
(
OPERATORS
)
==
len
(
WEIGHTS
)
P_OPEN_BRACKET
=
0.2
P_NOT
=
0.2
#P_LOGIC_NOT = 0.15
P_CLOSE_BRACKET
=
0.
25
P_CLOSE_BRACKET
=
0.
3
ERROR_LITERAL
=
"
!err!
"
QUOTATION_MARKS
=
"
\"
"
...
...
@@ -35,6 +36,8 @@ def get_question(length=4, operators=OPERATORS, brackets=True, conditions=False,
- length: num of literals that are connected via operators
"""
assert
all
([
o
in
OPERATORS
for
o
in
operators
]),
"
Es wurden Operatoren angegeben, die nicht erlaubt sind, vgl. ALLOWED_OPERATORS
"
weights
=
tuple
([
WEIGHTS
[
i
]
for
i
in
range
(
len
(
WEIGHTS
))
if
OPERATORS
[
i
]
in
operators
])
assert
len
(
operators
)
==
len
(
weights
)
question_contains_errors
=
True
while
question_contains_errors
:
string
=
""
# that's how it all starts
...
...
@@ -58,7 +61,7 @@ def get_question(length=4, operators=OPERATORS, brackets=True, conditions=False,
string
+=
"
)
"
num_brackets
-=
1
string
+=
"
"
# between literal and operator
string
+=
random
.
choice
(
operators
)
string
+=
random
.
choice
s
(
operators
,
weights
)[
0
]
string
+=
"
"
# between operator and literal (next loop)
string
+=
random
.
choice
(
literals
)()
# last literal
string
+=
"
)
"
*
num_brackets
# close all brackets
...
...
@@ -457,7 +460,7 @@ def main():
while
1
:
print
(
"
\n
----------------------
\n
"
)
# seperator
# get a question
q
=
get_question
(
length
=
14
)
q
=
get_question
()
num_question
+=
1
# ask the question
print
(
f
"
Frage
{
num_question
}
:
"
+
q
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment