我想像这样给Ruby整数输入:
12 343 12312 12312 123123 231
12 343 12312 12312 123123 243
12 343 12312 12312 123123 2123
Run Code Online (Sandbox Code Playgroud)
整个事情应该被视为一个数字,以便我可以对它们进行排序,如果有任何重复的数字,我想打印它们.应将整行视为整数,以便与其他行进行比较.我无法将输入转换为一个整数,对于它给我的每一行都是12.我怎样才能做到这一点?
我正在使用这样的Ruby输入:
lines = STDIN.readlines.map{|x| x.strip.to_i}.sort
Run Code Online (Sandbox Code Playgroud)
这从命令提示符获取输入,但我想输入特定次数.假设我的测试用例数为3,如何在3行输入后停止测试?
我想开发一个python桌面应用程序,它可以在facebook,twitter或gtalk上作为消息进行交互和发布.有可能吗?...教程和想法会有所帮助
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<title>Drag Feature Example</title>
<link rel="stylesheet" href="../theme/default/style.css" type="text/css" />
<link rel="stylesheet" href="style.css" type="text/css" />
<style type="text/css">
#controls {
width: 512px;
}
#controlToggle {
padding-left: 1em;
}
#controlToggle li {
list-style: none;
}
</style>
<script src="../OpenLayers.js"></script>
<script type="text/javascript">
var map, vectors, controls;
function init(){
map = new OpenLayers.Map('map');
var wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://vmap0.tiles.osgeo.org/wms/vmap0?", {layers: 'basic'});
vectors = new OpenLayers.Layer.Vector("Vector Layer");
map.addLayers([wms, vectors]);
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.addControl(new …Run Code Online (Sandbox Code Playgroud) 尝试做一个接受这个的字符串匹配有点困惑:
让我们说字符串S ="下载"在这里,S可以是"下载"或"下载"或"DoWNload".因此,字符串中的任何字符都可以是大写或小写.它很容易为所有大写字母或所有小写字母甚至是混合字母编写正则表达式匹配,但我发现很难编写遵循特定顺序的正则表达式匹配,这里是"下载".
我希望我在这里很清醒.
'WSGIRequest'对象没有属性'username'这是我得到的错误.我已经完成了与之相关的大部分问题,并做了相应的更改.但是还没有遇到解决方案.在我的settings.py中就是这样
TEMPLATE_CONTEXT_PROCESSORS = ( "django.core.context_processors.debug", "django.core.context_processors.i18n")
TEMPLATE_CONTEXT_PROCESSORS += (
'django.core.context_processors.request',
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.static',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
)
AUTH_PROFILE_MODULE = "prof.userprofile"
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.doc.XViewMiddleware',
)
Run Code Online (Sandbox Code Playgroud)
我想知道这个错误意味着什么,因为这是我第一次遇到这样的错误.以及如何调试它?编辑:
Exception Value:
'WSGIRequest' object has no attribute 'username'
Exception Location: /home/satyajit/geodjango/geographic_admin/prof/views.py in view_foo, line 18
Run Code Online (Sandbox Code Playgroud)
这是我的views.py
from django.shortcuts import render_to_response
from django.contrib.gis.shortcuts import render_to_kml
from django import forms
from django.contrib.auth.models import User
from django.shortcuts import get_object_or_404, render_to_response
from django.http import HttpResponseRedirect, HttpResponse
from django.contrib.auth.decorators import login_required
@login_required
def view_foo(request):
user1 = …Run Code Online (Sandbox Code Playgroud) >>> a=("-2","-2")
>>> float(a[0][0])
Run Code Online (Sandbox Code Playgroud)
这给了我一个错误
ValueError: invalid literal for float(): -
Run Code Online (Sandbox Code Playgroud)
那么我该如何转换呢?
使用时round(2.9239,2),它产生输出2.99999999而不是2.92.在stackoverflow中,我已经读过,处理这个的最好方法是在输出上使用字符串格式.如果这是唯一的方法,为什么我们甚至有一个圆函数?所有数字都不一致.正如在某些数字中,它给出了正确的输出,对于某些数字它没有.
在C中,我有一个字符数组:
d[20]
Run Code Online (Sandbox Code Playgroud)
使用空终止字符为"if"赋值:
d[0]='i'
d[1]='f'
d[2]='\0'
Run Code Online (Sandbox Code Playgroud)
该值应strcmp(d,"if")为0吗?为什么?
我希望strcmp返回值0.当我运行它时,我得到值-1