我应该在两个行中得到相同的...发生了什么我得到两个不同的值...就像它针对的是不同的位置..我认为错误在于 d->add(*b)
输出是
thiago 14333804
Ph¿?? 2816532
Run Code Online (Sandbox Code Playgroud)
更好地描述它我把下面的代码
我有一个程序
int main(int argc, char **argv) {
CClass* c = new CClass();
BClass* b = c->getNext();
printf("%s %d \n", b->getValue(), b->getValue());
DClass* d = new DClass();
d->add(*b);
printf("%s %d \n", d->getNext(), d->getNext());
cin.get();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
接口如下
class BClass
{
private:
char* value;
bool stale;
public:
BClass(char* value);
~BClass(void);
char* getValue();
bool isStale();
};
class CClass
{
private:
vector<BClass*> list;
public:
CClass(void);
~CClass(void);
BClass* getNext();
};
class DClass
{
private:
vector<BClass*> list; …Run Code Online (Sandbox Code Playgroud) 我运行了这段代码并得到如下错误:
Traceback (most recent call last):
File "urllister.py", line 26, in <module>
for k in l: print k,"points to",l[k],"\n"
RuntimeError: dictionary changed size during iteration
Run Code Online (Sandbox Code Playgroud)
我唯一要做的就是在第27行的for循环中打印
from sgmllib import SGMLParser
class URLLister(SGMLParser):
def reset(self):
SGMLParser.reset(self)
self.data = []
def start_a(self, attrs):
href = [v for k , v in attrs if k == 'href']
if href:
self.data.extend(href)
if __name__ == '__main__':
import urllib
sock = urllib.urlopen("http://diveintopython.org")
parser = URLLister()
html = sock.read()
parser.feed(html)
sock.close()
parser.close()
for url in parser.data: print …Run Code Online (Sandbox Code Playgroud) 我在python中编写了一个函数,它接受一个时间戳并将时间戳wrt返回到当前时区.
码
def datetime_from_utc_to_local(utc_datetime):
now_timestamp = time.time()
offset = datetime.fromtimestamp(now_timestamp) - datetime.utcfromtimestamp(now_timestamp)
return utc_datetime + offset
Run Code Online (Sandbox Code Playgroud)
错误:
unsupported operand type(s) for +: 'int' and 'datetime.timedelta'
Run Code Online (Sandbox Code Playgroud)
你能帮我修一下这个错误.
我希望此函数返回时间戳
我试图解决无限猴子定理,这是我在网上遇到的编程任务的一部分.
问题陈述是:
该定理指出,猴子在打字机键盘上随机敲击键无限时间几乎肯定会输入一个给定的文本,例如威廉·莎士比亚的全集.好吧,假设我们用Python函数替换猴子.你认为Python函数生成莎士比亚的一个句子需要多长时间?我们要拍的句子是:"它就像狡猾的人一样"
我试图看a)是否有可能生成字符串b)生成字符串后迭代次数
我已经将递归限制设置为10000,查看之前的SO问题,但我仍然得到达到最大递归深度的运行时错误.
我仍然在寻找python的方法.我希望看到有关如何以更好的方式做到这一点的建议,而不会遇到递归深度问题.
到目前为止,这是我的代码:
import random
import sys
alphabet=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',' ']
quote="methinks it is like a weasel"
msg='cont'
count=0
sys.setrecursionlimit(10000)
def generate(msg):
sentence=''
while len(sentence)!=27:
#random.choice() prints a random element from list 'alphabet'
sentence=sentence+random.choice(alphabet)
if msg=='cont':
verify(sentence)
def verify(msg2):
global count
if msg2.find(quote)==-1:
count+=1
generate('cont')
else:
print 'sentence is ',msg2 ,'count is',count
if __name__ == '__main__':
generate(msg)
Run Code Online (Sandbox Code Playgroud) #include <stdio.h>
int findnumb(int max)
{
static int total=2;
static int desk=1;
if(total>max)
{
return 0;
}
else
{
if(desk>=total)
{
total++;
desk=1;
return findnumb(max);
}
else
{
desk++;
int left=desk*(desk-1)/2;
int right=(total*(total+1)/2)-(desk*(desk+1)/2);
if(left==right)
{
printf("Desk number %d, number of participants %d\n", desk, total);
return findnumb(max);
}
return findnumb(max);
}
}
}
main()
{
int max;
printf("Enter the upper bound:\n");
scanf(" %d", &max);
printf("------------------------\n");
findnumb(max);
printf("Search is complete");
}
Run Code Online (Sandbox Code Playgroud)
这是一个像这样的谜语:
假设存在会议,我们不知道有多少人参加会议.但是,我们看到一个人退出会议.如果我们问这个人在会议上有多少人,他只回答"我不知道".尽管如此,他还是说"我正坐在一张编号为x的椅子上,而且我和我之上的数字总和相等.换句话说,如果椅子的数量是x,那么1,2,3 ...... .x-1 = x + 1 x + 2 …
我正在尝试新建这个对象的实例:
class MyAwesomeRealmObject: BaseRealmObject {
var field: String = ""
var thing: String = ""
var whatever: String = ""
var something: String = ""
var key: String = ""
var cards = [OtherRealmObject]()//wasnt this either
override static func primaryKey() -> String? {
return "key"
}
// override static func ignoredProperties() -> [AnyObject] {
// return ["id"] //this didnt work either
// }
}
Run Code Online (Sandbox Code Playgroud)
这是父类
class BaseRealmObject: Object {
//nothing really here, just extending realm's Object
}
Run Code Online (Sandbox Code Playgroud)
我得到了这个运行时异常.
2015-08-19 10:03:53.388 …Run Code Online (Sandbox Code Playgroud) 我不知道这个错误。我从Google开发人员控制台获得了这些消息。z3,htc m8,m9等某些设备无法执行我的应用。有人可以给我一些有关该错误的提示吗?
堆栈跟踪 :
java.lang.RuntimeException: Unable to start activity ComponentInfo{package name/package name.SettingsActivity}: android.view.InflateException: Binary XML file line #31: Error inflating class com.android.internal.widget.ActionBarContainer
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2499)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2563)
at android.app.ActivityThread.access$800(ActivityThread.java:162)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1438)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:209)
at android.app.ActivityThread.main(ActivityThread.java:5900)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1005)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:800)
Caused by: android.view.InflateException: Binary XML file line #31: Error inflating class com.android.internal.widget.ActionBarContainer
at android.view.LayoutInflater.createView(LayoutInflater.java:633)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:3659)
at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3755)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:403)
at android.app.Activity.setContentView(Activity.java:2174)
at android.preference.PreferenceActivity.onCreate(PreferenceActivity.java:553)
at …Run Code Online (Sandbox Code Playgroud) 我得到了这个函数来预测输出.这是说参考错误,我还在想为什么?
if(function x(){console.log("ABC");})
{
x();
}
Run Code Online (Sandbox Code Playgroud)
希望有人可以对词汇范围有所了解.提前致谢.
我写了一个新函数,当我执行它时,我收到一个错误:
<function read_grades at 0x000001F69E0FC8C8>
好的,这是我的代码:
def add(x, y):
z = x / y * 100
return z
def calc_grade(perc):
if perc < 50:
return "1"
if perc < 60:
return "2"
if perc < 75:
return "3"
if perc < 90:
return "4"
if perc >= 90:
return "5"
def calc_command():
num1 = input("Input your points: ")
num2 = input("Input maximum points: ")
num3 = add(float(num1), float(num2))
grade = calc_grade(num3)
print("This is your result:", str(num3) + "%")
print("Your grade:", …Run Code Online (Sandbox Code Playgroud) 我想编写一个输出从1到n的数字列表的函数:[1,2,... n],我知道可以做到,[1..n]但是我想做一个自己的函数:
addtimes n = addtimes_ [] n
addtimes_ [lst] a =
if a < 1
then [lst]
else addtimes_ [a:lst] (a-1)
main =
print $ addtimes 10
Run Code Online (Sandbox Code Playgroud)
尽管上面的代码可以编译并运行,但是会出现以下运行时错误:
testing: testing.hs:(3,1)-(6,37): Non-exhaustive patterns in function addtimes_
Run Code Online (Sandbox Code Playgroud)
问题在哪里,如何解决?
runtime-error ×10
python ×4
android ×1
c ×1
c++ ×1
entity ×1
function ×1
haskell ×1
if-statement ×1
ios ×1
javascript ×1
pointers ×1
preference ×1
python-3.x ×1
realm ×1
recursion ×1
runtime ×1
swift ×1