如何批量删除负数中的负号

时间:2019-01-28 18:11:02

标签: batch-file random numbers echo symbols

我正在设置一行文本,告诉您是否丢失或获得了某些东西,但是只要值是负数,(-)符号就始终存在。我试图搜索如何解决此问题,但未发现任何问题。

:grocerycomplete
set /a randomsurvivors=%random% %%3 - 1
if %randomsurvivors% LSS 0 (
    set porn=lost
) else (
    set porn=gained
)
echo ========================
echo You have looted the Grocery Store!
echo You have %porn% %randomsurvivors% Survivor(s)!

“ randomsurvivors”生成一个介于1和-1之间的数字。

  

然后读取该数字,如果该数字<0,则表示丢失;如果该数字> 0,则表示获得。每当它为-1时都会说:   

========================
You have looted the Grocery Store!
You have lost -1 Survivor(s)!

我要说:

========================
You have looted the Grocery Store!
You have lost 1 Survivor(s)!

1 个答案:

答案 0 :(得分:2)

仅需很小的改动(最后一行3个字符):

 np.where(np.diff(np.sign(np.gradient(x))) > 0)[0][0]+2   #add 2 as each time you call np.gradient or np.diff you are substracting 1 in size, the first [0] is to get the positions, the second [0] is to get the "first" element
>> 8
x[np.where(np.diff(np.sign(np.gradient(x))) > 0)[0][0]+2]
>> 0.03420759

使用substring substitution:grocerycomplete set /a randomsurvivors=%random% %%3 - 1 if %randomsurvivors% LSS 0 ( set porn=lost ) else ( set porn=gained ) echo ======================== echo You have looted the Grocery Store! echo You have %porn% %randomsurvivors:-=% Survivor(s)! 替换为空白。

相关问题