我必须在Python中找到列表的平均值.到目前为止这是我的代码
l = [15, 18, 2, 36, 12, 78, 5, 6, 9]
print reduce(lambda x, y: x + y, l)
Run Code Online (Sandbox Code Playgroud)
我已经得到它所以它将列表中的值加在一起,但我不知道如何将它分成它们?
以降序显示数据的最有效方法是什么?
public String getRank() {
String[] rank = new String[]{ KEY_ROWID };
Cursor c = scoreDb.query(DATABASE_TABLE, rank, null, null, null, null, null); //reading information from db.
String rankResult = "";
int iRow = c.getColumnIndex(KEY_ROWID); //Cursor looking for column setting equal to these ints.
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
//Move to first row - where cursor starts and moves to next row as long it is not after last row.
rankResult = rankResult + c.getString(iRow) + "\n";
//Returning value of row …Run Code Online (Sandbox Code Playgroud) 我在我的Android应用程序中有一个webview,但是当有人在网站上导航时,它会在新窗口中打开,我希望它保留在webview中..有没有办法轻松地做到这一点?这是我活动中的代码:
super.onCreate(savedInstanceState);
setContentView(R.layout.shop);
WebView webview;
webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("http://www.google.co.uk");
Run Code Online (Sandbox Code Playgroud) 我在我的Android应用程序中使用webview,在应用程序启动的那一刻,网站被放大了很多,我希望它被缩小以适应屏幕的宽度.我目前在我的活动中有这个:
super.onCreate(savedInstanceState);
setContentView(R.layout.shop);
WebView webview;
webview = (WebView) findViewById(R.id.webview);
webview.setWebViewClient(new WebViewClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("http://www.example.com");
Run Code Online (Sandbox Code Playgroud) 我创建了一个html表单
<form action="http://localhost/php/insert.php" method="post">
Barcode: <input type="text" name="barcode" /><br><br>
Serial: <input type="text" name="serial" /><br><br>
<input type="submit" />
</form>
Run Code Online (Sandbox Code Playgroud)
使用这个PHP保存到我的数据库:
<?php
$con = mysql_connect("example","example","");
if ( ! $con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("database", $con);
$sql = "INSERT INTO asset (barcode, serial)
VALUES ('$_POST[barcode]','$_POST[serial]')";
if ( ! mysql_query($sql, $con)) {
die('Error: ' . mysql_error());
}
mysql_close($con)
?>
Run Code Online (Sandbox Code Playgroud)
表单保存到数据库但页面只是http://localhost/php/insert.php按下提交,这是一个空白页面.如何让它保持在同一页面上只显示消息或其他内容?
我目前有以下代码:
- @alpha = Glossary.find(:all, :order =>"title ASC").group_by{|u| u.title[0]}
- @glossary = Glossary.find(:all, :order =>"title ASC")
- @alpha.each do|a|
%h1= a[0]
- @glossary.each do |g|
%p display stuff
Run Code Online (Sandbox Code Playgroud)
这显示了每个字母下的所有术语表术语,而不仅仅是以字母开头的术语.我尝试过一些东西,但我不确定如何选择正确的东西.
当我尝试运行我的视图时,我得到了这个:
Missing template application/login with {:formats=>[:html], :locale=>[:en], :handlers=>[:coffee, :erb, :builder]}. Searched in: * "/home/carladessi/Goods In Final/app/views"
Run Code Online (Sandbox Code Playgroud)
在我的控制器中我有:
def login
# respond_to do |format|
# format.html
end
Run Code Online (Sandbox Code Playgroud)
在我的路线我有:
match "/login/", :controller => 'application', :action => 'login'
Run Code Online (Sandbox Code Playgroud)
我猜我需要在控制器中加入其他东西我只是不知道是什么...抱歉,如果这是一个非常明显的问题!
我需要将所有内容从一个表导出到CSV文件中,之前我使用过更快的CSV gem,但它已停止使用较新版本的rails.有没有人有另一种方式可以使用?
给定color = ["red","blue","green","yellow","purple","orange","white","black"]生成并打印50种随机颜色的列表.您将需要使用随机模块来获取随机数.使用范围和地图生成所需的数字量.然后使用map将数字转换为颜色.打印结果.
这是一个我已经给出的问题,到目前为止这是我的代码
colour = [ "red", "blue", "green", "yellow", "purple", "orange", "white", "black" ]
number=random.randint(1,9)
number.range(50)
Run Code Online (Sandbox Code Playgroud)
我假设这个变量在1-9之间选择随机数,然后生成其中的50个?我现在需要一些方法将数字与颜色联系起来..我知道这个问题很模糊,但如果有人能指出我正确的方向,那就太棒了!
这是我嵌套表单的相关部分:
<div class="field">
<%= f.fields_for "@partcode" do |p|%>
<%= p.label "partcode"%><br />
<%= p.text_field :partcode %>
<% end %>
</div>
Run Code Online (Sandbox Code Playgroud)
我已经在我的模型中有这个:
attr_accessible :partcode,
:description
Run Code Online (Sandbox Code Playgroud)
但当我在表单中输入内容时,我收到此错误:
Can't mass-assign protected attributes: @partcode
Run Code Online (Sandbox Code Playgroud)
这是我的零件代码模型:
class Partcode < ActiveRecord::Base
attr_accessible :partcode,
:description
validates :partcode,
:description,
:presence => true
belongs_to "goods_ins"
accepts_nested_attributes_for "goods_ins"
end
Run Code Online (Sandbox Code Playgroud)
这是我的商品在模型中的所有代码:
class GoodsIn < ActiveRecord::Base
attr_accessible :c4lpono,
:courier,
:deliverydate,
:deliverynoteno,
:description,
:destination,
:notes,
:partcode,
:quantity,
:signedby,
:suppliername
validates :deliverydate,
:deliverynoteno,
:destination,
:quantity,
:signedby,
:suppliername,
:presence => true
has_many :suppliers
has_many :partcodes …Run Code Online (Sandbox Code Playgroud)