如何计算系列1 + 1/1!+ 1/2!+ 1/3!+ ... + 1/N!在C++中?我有一个大纲:
#include <iostream>
using namespace std;
int main()
{
int n, i, j, fat;
float soma = 0.0;
cin >> n;
for (i = 1; i <= n; i++)
{
fat = 1;
soma += 1 / fat;
for (j = 1; j <= n; j++)
{
fat *= j;
}
}
cout << soma << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud) 如何从条件中将注释作为单元格返回.
例:
=if(a1=0;insert comment on cell)
Run Code Online (Sandbox Code Playgroud)
插入评论并显示评论
我尝试在模板中返回计数注册以进行销售。我使用列表视图。我需要销售的返回计数寄存器。
我试试
#models.py
class Sale(models.Model):
customer = models.ForeignKey(Customer)
...
def __unicode__(self):
return unicode(self.date_sale)
...
@property
def get_counter(self):
return Sale.objects.count()
#views.py
class SaleList(ListView):
template_name = 'sale_list.html'
model = Sale
context_object = 'sale_list'
paginate_by = 10
#sale_list.html
{{ sale.get_counter }}
Run Code Online (Sandbox Code Playgroud)
但不工作。
如何返回销售计数寄存器?
考虑这个模型
class Dealership(models.Model):
dealership = models.CharField(max_length=50)
class Ordered(models.Model):
customer = models.ForeignKey("Customer")
dealership = models.ManyToManyField("Dealership")
status = models.CharField(max_length=2, choices=status_list, default='p')
Run Code Online (Sandbox Code Playgroud)
我试试
$ ./manage.py shell
>>> from new_way.core.models import Ordered, Dealership
>>> q = Ordered.objects.all()[:5]
>>> [i.dealership for i in q.dealership.all]
Run Code Online (Sandbox Code Playgroud)
并产生错误
Traceback (most recent call last):
File "<console>", line 1, in <module>
AttributeError: 'QuerySet' object has no attribute 'dealership'
Run Code Online (Sandbox Code Playgroud)
如何返回
Ordered.dealership.dealership
Run Code Online (Sandbox Code Playgroud)
所有经销商均已订购。
在我的代码中,日期之间的差异是错误的,因为它应该是38天而不是8天.我该怎么办?
package random04diferencadata;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Random04DiferencaData {
/**
* http://www.guj.com.br/java/9440-diferenca-entre-datas
*/
public static void main(String[] args) {
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm dd/mm/yyyy");
try {
Date date1 = sdf.parse("00:00 02/11/2012");
Date date2 = sdf.parse("10:23 10/12/2012");
long differenceMilliSeconds = date2.getTime() - date1.getTime();
System.out.println("diferenca em milisegundos: " + differenceMilliSeconds);
System.out.println("diferenca em segundos: " + (differenceMilliSeconds / 1000));
System.out.println("diferenca em minutos: " + (differenceMilliSeconds / 1000 / 60));
System.out.println("diferenca em horas: " + (differenceMilliSeconds / 1000 / …Run Code Online (Sandbox Code Playgroud) 如何在django中的CreateView中使用上下文?
在我之前:
#views.py
from django.views.generic import CreateView
from cars.models import *
def CreateCar(CreateView):
info_sended = False
if request.method == 'POST':
form = FormCar(request.POST, request.FILES)
if form.is_valid():
info_sended = True
form.save()
else:
form = FormCar()
ctx = {'form': form, 'info_sended':info_sended}
return render_to_response("create_car.html", ctx,
context_instance=RequestContext(request))
Run Code Online (Sandbox Code Playgroud)
现在,有了,并尝试:
class CreateCar(CreateView):
info_sended = False
template_name = 'create_car.html'
model = Car
success_url = 'create_car' #urls name
def form_valid(self, form):
info_sended = True
ctx = {'form': form, 'info_sended':info_sended}
return super(CreateCar, self).form_valid(form)
Run Code Online (Sandbox Code Playgroud)
我的html页面是:
<!-- create_car.html -->
{% extends …Run Code Online (Sandbox Code Playgroud) Django模板中的搜索字段
如何在Django Template中创建与此图像类似的搜索字段
http://asciicasts.com/system/photos/1204/original/E354I01.png
我在github中尝试这个 https://github.com/rg3915/vendas/commit/e0c67fd8154a3b8e450ec3db38705cdd7efc1350
但我不知道如何完成.
看我的GitHub
https://github.com/rg3915/gallery
如何在Django模板上渲染图像?但他回来了:
画廊
媒体/ 3665_1280x800_8UX8tgG.jpg
环法自行车赛
媒体/ 281405_fSRBDZu.jpg
儿童自行车
如何渲染图像?
该错误是否在settings.py中
Java:如何打印矢量?
import java.util.Scanner;
public class Ed04VetorOrdenado {
public static void main(String[] args) {
Scanner entrada = new Scanner(System.in);
int vet[] = new int[10];
System.out.println("Digite 10 numeros:");
for (int i = 0; i < vet.length; i++) {
vet[i] = entrada.nextInt();
}
System.out.print("Vetor ordenado: ");
ordenar(vet);
}
// Buble sort function
static void ordenar(int[] v) {
int troca;
for (int i = 0; i < v.length; i++) {
for (int j = i + 1; j < v.length; j++) {
if (v[i] …Run Code Online (Sandbox Code Playgroud) django ×4
java ×2
algorithm ×1
c++ ×1
comments ×1
date ×1
django-views ×1
excel ×1
field ×1
imagefield ×1
many-to-many ×1
printing ×1
python ×1
search ×1
vector ×1