我刚刚学习Codeacademy的程序.我有一个任务,但无法弄清楚我做错了什么.
首先,我需要定义一个返回值的多维数据集的函数.然后我应该定义第二个函数,检查一个数字是否可被3整除.如果是,我需要返回它,否则我需要返回False
.
继承人代码:
def cube(c):
return c**3
def by_three(b):
if b % 3 == 0:
cube(b)
return b
else:
return False
Run Code Online (Sandbox Code Playgroud) >>> a = 0.3135
>>> print("%.3f" % a)
0.314
>>> a = 0.3125
>>> print("%.3f" % a)
0.312
>>>
Run Code Online (Sandbox Code Playgroud)
我期待0.313而不是0.312任何想到为什么会这样,是否有替代方式我可以用来获得0.313?
谢谢
我一直在试图围绕SDL的基础知识,我对看似简单的东西感到难过.
SDL_MapRGB()
需要const SDL_PixelFormat*
,我用SDL_PixelFormatEnum
我的项目创建纹理unit32
.但我找不到任何转换它的方法SDL_MapRGB()
.
这可能比使用更简单SDL_MapRGB()
,但这个问题仍然会让我感到困惑,因为你可以轻松地将其转换为另一种方式.
不相关,但是如果你想知道剩下的代码,那么你就去吧.
#include <SDL.h>
SDL_Window *sdlWindow;
SDL_Renderer *sdlRenderer;
int main( int argc, char *args[] )
{
int w = 640;
int h = 480;
Uint32 format = SDL_PIXELFORMAT_RGB888;
SDL_CreateWindowAndRenderer(w, h, 0, &sdlWindow, &sdlRenderer);
SDL_Texture *sdlTexture = SDL_CreateTexture(sdlRenderer, format, SDL_TEXTUREACCESS_STREAMING, w, h);
extern uint32_t *pixels;
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
pixels[x + …
Run Code Online (Sandbox Code Playgroud) 有谁知道如何使用win32com在电子邮件中添加电子邮件签名?
import win32com.client as win32
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = 'TO'
mail.Subject = 'SUBJECT'
mail.HTMLbody = 'BODY'
mail.send
Run Code Online (Sandbox Code Playgroud) 我需要split
使用foldr
split :: Eq a ? a ? [a] ? [[ a ]]
Run Code Online (Sandbox Code Playgroud)
例子:
split '/' ”hello/my/friends” ----> [”hello”,”my”,”friends”]
Run Code Online (Sandbox Code Playgroud)
这是我尝试过的:
split :: Eq a ? a ? [a] ? [[ a ]]
split str delim = let (start, end) = break (== delim) str
in start : if null end then [] else groupBy (tail end) delim
Run Code Online (Sandbox Code Playgroud) 我有一个函数返回看起来像这样的结果:
(({:one 1}) ({:two 2} ({:three 3} {:four 4})))
Run Code Online (Sandbox Code Playgroud)
是否有一种简单/惯用/有效的方法将上面的列表展平为一个列表:
({:one 1} {:two 2} {:three 3} {:four 4})
Run Code Online (Sandbox Code Playgroud)
map
忽略列表级嵌套的函数,并在叶子上运行?reduce
而不是map
)试图从字符串中读取哈希映射,但如果键是"关键字"类型值,我从cljs.reader/read-string得到错误.从字符串中读取哈希映射的正确方法是什么?
此版本没有关键字工作:
(cljs.reader/read-string (pr-str {1 "a", 1481876814936 "sdafa", 1481876816039 "afdas", 1481876817344 "asdfa", 2 "b"}))
=> {1 "a", 1481876814936 "sdafa", 1481876816039 "afdas", 1481876817344 "asdfa", 2 "b"}
Run Code Online (Sandbox Code Playgroud)
但是这个带有关键字的版本会抛出错误:
(cljs.reader/read-string (pr-str {:1 "a", :1481876814936 "sdafa", :1481876816039 "afdas", :1481876817344 "asdfa", :2 "b"}))
cljs.user=> #object[TypeError TypeError: Cannot read property '0' of null]
TypeError: Cannot read property '0' of null
at cljs$reader$read_keyword (file:///test/resources/public/js/ui-out/cljs/reader.js:681:19)
at cljs$reader$read_delimited_list (file:///test/resources/public/js/ui-out/cljs/reader.js:397:20)
at cljs$reader$read_map (file:///test/resources/public/js/ui-out/cljs/reader.js:466:41)
at cljs$reader$read (file:///test/resources/public/js/ui-out/cljs/reader.js:879:34)
at cljs$reader$read_string (file:///test/resources/public/js/ui-out/cljs/reader.js:911:25)
at eval (eval at figwheel$client$utils$eval_helper (file:///test/resources/public/js/ui-out/figwheel/client/utils.js:143:8), <anonymous>:1:114)
at eval (eval at …
Run Code Online (Sandbox Code Playgroud) 我正在使用emgu cv 3.0.0,我想从USB摄像头捕获帧.不幸的是,我在调用Image<Bgr, Byte> image = capture.QueryFrame();
It时遇到错误,我无法转换Emgu.CV.Mat
为Emgu.CV.Image
.
这是我的clojure代码:
(defn salutation-adder-maker
([salutation call]
(def call (salutation-adder-maker salutation)))
([salutation]
#(str % salutation))
)
(salutation-adder-maker "-Thanks!" salutation1)
(salutation1 "Help me!")
Run Code Online (Sandbox Code Playgroud)
底部的两行代码给出了无法解析符号的错误salutation1
.函数编译很好,但这是因为它将函数定义为call
.因此以下代码有效:
(call "Help me!")
Run Code Online (Sandbox Code Playgroud)
它吐了出来
Help me-Thanks!
Run Code Online (Sandbox Code Playgroud)
而不是salutation1
具有该功能的功能.如何更改代码以便salutation1
执行与call
当前相同的操作?
我希望能够传递两个参数:
例如:
(salutation-adder-maker "-Have a good day!" day_salutation)
(day_salutation "I will talk to you later")=>"I will talk to you later-Have a good day!"
Run Code Online (Sandbox Code Playgroud) 我想使用下一个代码从clojure上的地图添加值:
(letfn [(r [l a]
(if (empty? l)
a
(if (map? l)
(r (first(vals l)) (+ a (first (vals l))))
(r (rest l) (+ a (first l))))))]
(r {:a 1 :b 2 :c 3} 0)
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:
IllegalArgumentException不知道如何从以下位置创建ISeq:java.lang.Long clojure.lang.RT.seqFrom(RT.java:542)