大家好!我正在解决一个问题,这就是问题:Why in python
(18 * 0.065325 - 20) * 6 / 1000 * 12 * 60 == -81.32032799999999
,
如果你放括号,那么
(18 * 0.065325 - 20) * (6 / 1000) * 12 * 60 == -81.320328
?
我读到了问题 0.1 + 0.2(这里),但我并没有真正理解我读到的所有内容如何适合我的问题。
大家好!我有一个包含以下代码的范围:
scope :tests_by_category, lambda { |category_name|
joins(:category)
.where(categories: { title: category_name })
.order(title: :desc)
}
问题是什么:当我想用 do..end 替换花括号时,特别是:
lambda do |category_name|
joins(:category)
.where(categories: { title: category_name })
.order(title: :desc)
end
lambda“丢失”块并引发错误
如果你写的不是 lambda,而是 ->(category_name) do...end,那么一切正常,但在这种情况下,rubokop 发誓,对于多行块,有必要将 -> 更正为 lambda。告诉我,为什么 lambda 完全“丢失”了块,是否有可能以某种方式修复它?
大家好!我正在做这个任务:/urls/:short_url 的 get-request 应该返回页面的 url 并将请求计数器增加 1(据我了解,这是需要的此类 get-requests 的数量计算)。为此,我实现了一个 Url 模型,其中包含 s_url:string 和 request_number:integer 字段以及控制器中 show 方法的以下代码:
def show
if !Url.where(s_url: request.original_url.to_s).blank?
url = Url.find_by_s_url(request.original_url.to_s)
url.request_number += 1
else
url = Url.create(s_url: request.original_url, request_number: 1)
url.save
end
render json: url, status: 200
end
这就是问题所在:计数器的值只被提升一次(从 1 到 2),然后它根本没有更新。此外,返回的正是最初更改的数据库行。如何解决?
我使用 VCL 中的多态性来实现形状(矩形、平行四边形和六边形)的旋转,使用从初始形状到下一个形状的过渡,以及形状本身。面临以下问题:级联出现以下错误:
它没有显示这发生在哪一行。但是,如果以某种方式快速从第一种形式移动到第二种形式并开始移动图形,则不会出现错误,这可能是什么原因?
我附上了表格的代码(除了最初的代码,那里没有什么有趣的):
unit Unit3;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, ComCtrls, ExtCtrls;
type
TForm3 = class(TForm)
Image: TImage;
Button1: TButton;
Timer1: TTimer;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormActivate(Sender: TObject);
private
public
end;
var
Form3: TForm3;
implementation
{$R *.dfm}
uses unit4;
var
t: single=0.0;
H: THexagon;
S: TSquare;
P: TParall;
Moving:Boolean=true;
procedure TForm3.Button1Click(Sender: TObject);
begin
close;
end;
procedure TForm3.FormActivate(Sender: TObject);
begin
H:=THexagon.Create(250,250,50,Image);
S:=TSquare.Create(475,250,50,Image);
P:=Tparall.Create(700,175,900,275, 150,Image);
Timer1.Enabled:=true;
end;
procedure TForm3.Timer1Timer(Sender: TObject);
begin
H.Move(t);
S.Move(-0.2*t);
P.Move(0.5*t);
t:=t+0.5;
end;
initialization
finalization
H.Free;
S.Free;
P.Free;
end.
以及具有多态性的形式:
Unit unit4;
Interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, ComCtrls, ExtCtrls;
Type
TFigure=Class
private
x, y, halflen, dx, dy: integer;
Image: TImage;
procedure Draw; virtual; abstract;
procedure Rel(t:real); virtual;
public
constructor Create(ax,ay,ah:integer;aImage:TImage);
procedure Move(t:single);
end;
THexagon=Class(TFigure)
private
r: integer;
procedure Draw; override;
public
constructor Create(ax, ay, ar: integer; aimage: timage);
end;
TSquare=Class(TFigure)
private procedure Draw; override;
end;
TParall=Class(TFigure)
private
h:integer;
x1, y1: integer;
procedure Draw;override;
public
constructor Create(ax,ay, ax1, ay1, ah: integer; aImage:TImage );
end;
Implementation
Constructor TFigure.Create;
Begin
inherited Create;
x := ax;
y := ay;
halflen := ah;
Image := aImage;
End;
Procedure TFigure.Rel;
Begin
dx := 0;
dy:=round(25*sin(t));
End;
Procedure TFigure.Move;
Begin
Image.Canvas.Pen.Color:=clWhite;
Draw;
Image.Canvas.Pen.Color:=clBlack;
Rel(t);
Draw;
End;
constructor THexagon.Create;
begin
inherited Create(ax,ay,ar,aImage);
r := ar;
end;
procedure THexagon.Draw;
var
p:array[1..7] of TPoint;
i:integer;
a:real;
begin
a:=0;
for i:=1 to 7 do begin
p[i].X:=x+round(r*cos(a));
p[i].Y:=y+dy-round(r*sin(a));
a:=a+pi/3;
end;
p[7]:=p[1];
with Image.Canvas do begin
brush.Style:=bsClear;
Polygon(p);
end;
end;
Procedure TSquare.Draw;
Begin
image.Canvas.rectangle(180,100+dy,230,150+dy);
End;
Constructor TParall.Create;
Begin
inherited Create(ax, ay, ah, aImage);
h := ah;
x1:= ax1;
y1:= ay1;
End;
Procedure TParall.Draw;
Begin
with image.Canvas do begin
moveto(x, y + dy);
lineto(x+h,y + dy);
lineto(x1, y1 + dy);
lineto(x1 - h, y1 + dy);
lineto(x, y + dy);
end;
End;
end.