I thought it would be nice for the player to pick their color.
My first attempt was:
define K = Character("Keeper")
define favcolor = (color="#ffffff")
define p1 = Character("Player1", (favcolor))
label start:
K "Got a favorite color?"
menu:
"Blue":
$ favcolor = color="#0033ff"
jump Style
"Red":
$ favcolor = color="#ff3300"
jump Style
"Yellow":
$ favcolor = color="#ffcc00"
jump Style
label Style:
p1 "Now I be styl'n"
but I get a syntax error. Likely because I have no idea what I'm doing.
It appears that an update has changed how this works. However, the following does work:
define K = Character("Keeper")
define E = Character('Eric', dynamic=True, color="#ffffff")
## The game starts here.
label start:
K "Got a favorite color?"
menu:
"Blue":
$ E = Character('Eric', color="#0000ff")
jump Style
"Red":
$ E = Character('Eric', color="#ff3300")
jump Style
"Yellow":
$ E = Character('Eric', color="#ffcc00")
jump Style
label Style:
E "Now I be styl'n"
I'll update the answer if, and when, I can find a better workaround.
Related
I want to pretty print an AST using Haskell and (currently) wl-pprint-annotated (willing to switch to a different library).
How can I make the renderer prefer breaking the softlines of the outer group over the softlines of the inner group?
Minimal Example
Take for example the tuple ((1234, 5678), (abcd, efgh)).
The output I want:
// line width: 10
(
(
1234,
5678
),
(
abcd,
efgh
)
)
// line width: 16
(
(1234, 5678),
(abcd, efgh)
)
// line width: 32
((1234, 5678), (abcd, efgh))
The output I get:
// line width: 10
((1234,
5678),
(abcd,
efgh))
// line width: 16
((1234, 5678), (
abcd, efgh))
// line width: 32
((1234, 5678), (abcd, efgh))
Code:
module Main where
import qualified Prelude
import Prelude hiding((<>))
import Text.PrettyPrint.Annotated.WL
main :: IO ()
main = do
putStrLn $ pp 10
putStrLn $ pp 16
putStrLn $ pp 32
pp w = "// line width: " ++ show w ++ "\n" ++
display (renderPretty 1.0 w doc) ++ "\n"
doc = pair (pair (text "1234") (text "5678"))
(pair (text "abcd") (text "efgh"))
pair x y = group (nest 2 (lparen <//> x <> comma </> y) <//> rparen)
pair x y = group (nest 2 (lparen <##> x <> comma <#> y) <##> rparen)
As ekim found out, I've mixed up </> with <#>
I found the documentation to be confusing, so let me clear it up a little.
First of all the operators </> and <#> are just sugar for line and softline.
See definitions:
x </> y = x <> softline <> y
x <#> y = x <> line <> y
My problem was that I was using softline when what I wanted was line.
Commonalities between line and softline
Both are printed as space when the whole line fits the page. Both are replaced with a line break when the line does not fit the page.
Difference between line and softline
When a group foes not fit the page, all lines of the whole group are replaced with line breaks. That's the behavior I've wanted.
When the line does not fit the page, only the last softline still fitting the page is replaced.
Not the whole group.
It's like the word wrapping in our text editors: Just breaking after the last word that fits to the page.
For example
doc = paragraph p1
paragraph = foldr (</>) mempty . map text . words
p1 = "I want to pretty print an AST using Haskell and (currently) wl-pprint-annotated (willing to switch to a different library)."
is printed as
I want to pretty print an AST using Haskell and
(currently) wl-pprint-annotated (willing to
switch to a different library).
I am trying to find the stat and p-value using shapiro function
I am formatting my results using .format but I am not able to understand why I am getting different results for below:
print ('stat = {0:.2f}'.format(stat), 'p = {0:.30f}'.format (p))
print ('stat = {0:.2f}, p = {0:.30f}'.format (stat,p))
first one prints 0.000000000000000268680677283857 (this is correct)
second one prints 0.974334061145782470703125000000
There is a mistake in the format string of the second example. Change the second format specification from {0:.30f} to {1:.30f}. With this style of formatting, when the first item in the format specification is a number, it indicates which positional argument of the format() method to print.
For example,
In [81]: stat = 0.974334061145782470703125
In [82]: p = 0.000000000000000268680677283857
In [83]: print('stat = {0:.2f}, p = {1:.30f}'.format(stat, p))
stat = 0.97, p = 0.000000000000000268680677283857
If you are using Python 3.6 or later, you might find it more convenient to use an f-string:
In [93]: print(f'stat = {stat:.2f}, p = {p:0.30f}')
stat = 0.97, p = 0.000000000000000268680677283857
The = format character allows an even more concise string expression:
In [101]: print(f'{stat = :.2f}, {p = :0.30f}')
stat = 0.97, p = 0.000000000000000268680677283857
Sorry english not first language:
I started python today in school and I can't figure this out, I am also specified to use procedural programming, so I can't call in classes like .textwrap or .format.
Here's the code:
x_max = 0
y_max = 0
menu = ["1. Somma", "2. Sottrazione", "3. Moltiplicazione", "4. Divisione", "5. Exit"]
y_max = len(menu)
for x in range(len(menu)):
p = len(menu[x])
if (x_max < p):
x_max = p
x_tabella = x_max
print("╔", end = '')
for x in range (x_tabella+4):
print ("═", end = '')
print ("╗")
for x in range(y_max):
print ("║ ", end = '')
print (menu[x], end = '') != x_max
print (" ║")
print("╚", end = '')
for x in range (x_tabella+4):
print ("═", end = '')
print ("╝")
The objective is to put a border, like a menu around the options, with the options centered in the borders. The problem is I don't know how to center it properly, cause the left side looks fine, but the right side is all off center. It's supposed to be a code where whatever option you put into the menu it extends and adapts the border.
This is how it ends up currently
I would really appreciate some help, thanks.
So I don't really understand your intention with this line:
print (menu[x], end = '') != x_max
But change it to:
print(menu[x] + ' '*(x_max-len(menu[x])), end = '')
And you should get the expected output.
s = "That that occurs sometimes. It sometimes means that which, and sometimes just that"
target = "that"
words = s.split()
b = []
for i,w in enumerate(words):
if w == target:
if i > 0:
b = words[i-1]
print([b].sep="",end",")
"I used, end=",sep=",but nothing worked.I need the output horizontally, with square brackets, commas and quotations marks. the brackets appear in the middle, and a comma at the end."
"Current output"
['That'],['means'],['just'],
"I need this output"
['That','means','just']
try this code it will work fine
s = "That that occurs sometimes. It sometimes means that which, and sometimes just that"
target = "that"
words = s.split()
b = []
for i,w in enumerate(words):
if w == target:
if i > 0:
b.append(words[i-1])
print(b,sep="")
It says the error is when h (altitude) is between 11000 and 25000, so I only posted the initial stuff outside all my if loops and the specific loop where the problem is happening. Here is my code:
import math;
T = 0.0;
P = 0.0;
hString = ("What is the altitude in meters?");
h = int(hString);
e = math.exp(0.000157*h);
elif 11000 < h < 25000:
T = -56.46;
P = (22.65)*[(1.73)-e];
When you use mathematical operations you need to be careful with brackets.
P = (22.65)*((1.73)-e); #will be right way of using
[ ] using will create a list which you, do not need in this program.
Here is a link which will help you learn much more about type conversions and proper use of brackets while doing mathematics on it.
Also in your code you have not used
hString =input ("What is the altitude in meters?");
h = int(hString);
input will allow you to take value from user and then int(your_input) will help you convert to integer
The square brackets in the last line ([(1.73)-e]) create a list. In this case, it's a list with one element, namely (1.73)-e. I imagine you intended those to be parens. Make that change and it will work.
The final line becomes:
P = (22.65)*((1.73)-e);