小编mkr*_*er1的帖子

python 在列表中打印出“\n”

我正在用 Python 处理一个项目,我想将一个列表串起来并打印出来。问题是,如果我尝试\n在新行中包含打印,程序会直接打印\n如下:

number_list = ["1\n", "2\n", "3\n"]
print(str(number_list))
Run Code Online (Sandbox Code Playgroud)

输出

number_list = ["1\n", "2\n", "3\n"]
print(str(number_list))
Run Code Online (Sandbox Code Playgroud)

想要的输出

['1\n', '2\n', '3\n']
Run Code Online (Sandbox Code Playgroud)

当列表被串起来时,如何使输出结束?

python python-3.x

0
推荐指数
1
解决办法
75
查看次数

如何将多个图合并到一张图中?

我需要一些帮助来将四个单独的图合并在一个页面上(单个图)。我使用相同的代码但使用不同的数据组绘制了四个不同的图。我需要在一页上绘制所有四个图。

library(ggpubr)
library(rstatix)
library(xlsx)
df<-read.xlsx("umar.xlsx", header = T, 1)
# Statistical test

######## Figure 1 ########
stat.test <- df %>%
  t_test(Moisture_content ~ substrate) %>%
  add_significance()
stat.test

# Box plots with p-values
bxp <- ggboxplot(df, x = "substrate", y = "Moisture_content", fill = "substrate", 
                 palette = c("#00AFBB", "#E7B800"), width = 0.35)



stat.test <- stat.test %>% add_xy_position(x = "substrate")
bxp + 
  stat_pvalue_manual(stat.test, label = "p = {p}") +
  scale_y_continuous(expand = expansion(mult = c(0.05, 0.1)))+
  theme(
    aspect.ratio = 3
  )


######## Figure 2 …
Run Code Online (Sandbox Code Playgroud)

r ggplot2

0
推荐指数
2
解决办法
2万
查看次数

加载不带文本限定符的字典

我必须加载一个 excel 文件,其中包含一个类似字典的字符串,不带文本限定符 ( ""),列中如下所示:

{Item: 0815, sequence: 1, qty: 3, name: some name, comapny: some company}, 
{Item: 4711, sequence: 2, qty: 4, name: some name, company: some company}
Run Code Online (Sandbox Code Playgroud)

我尝试使用以下语句创建字典:

item_string = dict(item_string)
Run Code Online (Sandbox Code Playgroud)

但我收到以下错误消息

ValueError:字典更新序列元素#0的长度为1;2 为必填项

有什么想法如何根据这个字符串创建字典吗?

python dictionary

0
推荐指数
1
解决办法
54
查看次数

有没有办法缩短我的口袋妖怪游戏的伤害计算?我不断重复代码行

正如你所看到的,当我计算造成的伤害时,我重复输入神奇宝贝。只是想知道是否有更简单的方法来编写这段代码。我想知道您是否可以使用某种表格,但不确定如何实现。为了以防万一,我已经提供了大部分课程。

class Pokemon:
    def __init__(self, name, types, max_health, health, attack, defense):
        self.name = name
        self.types = types
        self.max_health = max_health
        self.health = health
        self.attack = attack
        self.defense = defense

    #Calculates the damage output depending on their attack and defense attributes
    def move(self, opponent):
        raw_dmg = 0
        choice = int(input("Choose your move: "))
        if choice == 1:
            raw_dmg = int((self.attack / opponent.defense) * 25)
        elif choice == 2:
            if accuracy(70):
                raw_dmg = int((self.attack / opponent.defense) * 40)
            else:
                raw_dmg = 0 …
Run Code Online (Sandbox Code Playgroud)

python oop

0
推荐指数
1
解决办法
453
查看次数

有没有办法写出字符“\”?

我目前正在在控制台中打印字符串并让它们随着时间的推移绘制函数,同时我想到通过使用 chars 使图形更加直观\|/。显然,这并不那么重要,但是在用代码写下来时

oscilated[t]='\';
Run Code Online (Sandbox Code Playgroud)

\0编译器立即开始抱怨,可能是因为 char 与字符串的有关。所以我的问题是我是否可以以另一种方式打印字符,或者这真的不可能吗?

c

0
推荐指数
1
解决办法
47
查看次数

与小于无穷大的最大浮点数相加得到无穷大的最小数是多少?

python中最大的数字应该是:

\n
l=2**(1023)*(2-2**(-52))\n
Run Code Online (Sandbox Code Playgroud)\n
\n

1.7976931348623157e+308

\n
\n

这可以通过指令验证:

\n
sys.float_info.max\n
Run Code Online (Sandbox Code Playgroud)\n
\n

1.7976931348623157e+308

\n
\n

不过请看下面的内容

\n
1.0000000000000000000000000001*l\n
Run Code Online (Sandbox Code Playgroud)\n
\n

1.7976931348623157e+308

\n
\n

现在:

\n
1.00006*l\n
Run Code Online (Sandbox Code Playgroud)\n
\n

信息

\n
\n

到底是怎么回事?对于哪个x发生 (1+ x -\xce\xb5) = 1.7976931348623157e+308 且 (1+ x ) = inf?

\n

更新:

\n

我相信在Python中触发无穷大的最大数字是

\n

sys.float_info.max + 0.5*epsilonsys.float_info.max + 0.51*epsilon

\n

其中 epsilon = $2^{-52}$ 是计算机的 epsilon。

\n

看看这个:

\n
l = sys_float_info.max\n(1+0.5*epsilon)*l\n
Run Code Online (Sandbox Code Playgroud)\n
\n

1.7976931348623157e+308

\n
\n
(1+0.51*epsilon)*l\n
Run Code Online (Sandbox Code Playgroud)\n
\n

信息 …

python floating-point

0
推荐指数
1
解决办法
181
查看次数

在 Vim 中编写 makefile 时如何摆脱红色突出显示

我正在编写一个 makefile,它不断突出显示选项卡后的每个单词。这是一个例子:

\n

在此输入图像描述

\n

这是我的 .vimrc 文件:

\n
filetype indent off  \nset tabstop=4\nset expandtab\nsyntax on  \ncolorscheme slate\nset ignorecase\nset number \nset nosmartindent\nset noswapfile\nset list\nset listchars=tab:>-,trail:`,extends:>,precedes:<\nset lcs+=space:\xc2\xb7\n
Run Code Online (Sandbox Code Playgroud)\n

我怎样才能去掉红色突出显示?我知道:syntax off会摆脱它,但它摆脱了各种有用的颜色变化。

\n

vim makefile

0
推荐指数
1
解决办法
296
查看次数

dart 支持非局部变量吗?

例如,在 Python 中我们有一个非局部特征:

nonlocal 关键字用于处理嵌套函数内的变量,其中变量不应属于内部函数。使用关键字nonlocal 来声明该变量不是局部的。

nonlocal 语句声明,每当我们更改名称 var 的绑定时,绑定都会在已绑定 var 的第一帧中更改。回想一下,如果没有非本地语句,赋值语句将始终在当前环境的第一帧中绑定名称。nonlocal 语句指示名称出现在环境中除第一个(局部)帧或最后一个(全局)帧之外的某个位置。

Dart中有类似的东西吗?

以下是来自 Python 的代码示例:

def make_withdraw(balance):
    """Return a withdraw function that draws down balance with each call."""
    def withdraw(amount):
        nonlocal balance                 # Declare the name "balance" nonlocal
        if amount > balance:
            return 'Insufficient funds'
        balance = balance - amount       # Re-bind the existing balance name
        return balance
    return withdraw
Run Code Online (Sandbox Code Playgroud)

我无法使用的 Dart 伪翻译nonlocal

makeWithdraw(balance) {
  //Return a withdraw function that draws down balance with each call. …
Run Code Online (Sandbox Code Playgroud)

python variables scope dart

0
推荐指数
1
解决办法
150
查看次数

为什么我的二叉树定义会出现解析错误?

当我在 Haskell 中输入以下代码时:

data BT a = Empty | Fork a (BT a) (BT a) 
  Empty :: BT a
  Fork  :: a -> BT a -> BT a -> BT a
Run Code Online (Sandbox Code Playgroud)

我明白了

错误:输入“::”时出现解析错误

我看不出问题是什么,如果我添加deriving (show)到顶行,它会更改为

错误:输入“空”时解析错误

haskell

0
推荐指数
1
解决办法
93
查看次数

过滤面积较小的轮廓区域

我想过滤掉面积较小的碳纳米管。但我得到了一个错误。过滤器的正确使用方法是什么?

代码

def drawCnts(img, cnts):
    cnts = filter(lambda cnt: cv2.contourArea(cnt)> 400, cnts) # adding this line gets error
    cv2.drawContours(img, cnts, -1, (0, 255, 0), 3)
    imshow(img)
Run Code Online (Sandbox Code Playgroud)
import imUtils
import configure as cfg
import cv2

folder = 'test_images/'
img = imUtils.imread(folder + '1.cr3')
gray = cv2.cvtColor(imUtils.toOpenCVU8(img.copy()), cv2.COLOR_BGR2GRAY)
thresh = cv2.adaptiveThreshold(gray,255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY_INV,27,9)
# apply close morphology
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (5, 5))
thresh = cv2.morphologyEx(thresh, cv2.MORPH_CLOSE, kernel)
imUtils.imshow(thresh, 'thresh')

(cnts, _) = cv2.findContours(thresh.copy(),
                                cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
imUtils.drawCnts(img.copy(), cnts)
Run Code Online (Sandbox Code Playgroud)

错误

import imUtils
import configure as …
Run Code Online (Sandbox Code Playgroud)

python opencv functional-programming filter

0
推荐指数
1
解决办法
358
查看次数