我正在尝试打印出一条消息.如果找不到字典中的单词,那么它应该打印出一条消息而不是给出错误.我的想法是什么
if bool(bool(dictionary[word])) == True:
return dictionary[word]
else:
print 'wrong'
Run Code Online (Sandbox Code Playgroud)
但是当我写一些不在字典中的东西时,它不起作用,而是它给出了类似的东西
Traceback (most recent call last):
File "<pyshell#34>", line 1, in <module>
translate_word('hous')
File "H:\IND104\final\Project 4 - Italian-Spanish Translator\trial 1.py", line 21, in translate_word
if bool(bool(dictionary[word])) == True:
KeyError: 'hous'
Run Code Online (Sandbox Code Playgroud)
那么如何打印出错误信息谢谢.
我一直在尝试想一种遍历单个链表的方法。
到目前为止,这是我所做的:
#include <iostream>
typedef struct node {
int data; // will store information
node *next; // the reference to the next node
};
int printList(node *traverse) {
if (traverse->next == NULL) {
return -1;
}
traverse=traverse->next;
printList(traverse);
cout << traverse->data << endl;
return 0;
}
int main() {
node *head = NULL;
for (int i = 0; i < 10; i++) {
node *newEntry = new node;
newEntry->data = i;
newEntry->next = head;
head = newEntry;
}
printList(head);
return …Run Code Online (Sandbox Code Playgroud) 最近我在接受采访时被问到了这个问题.我所能做的就是从0到9的链表中从9遍历到1.这是代码:
#include <iostream>
typedef struct node {
int data; // will store information
node *next; // the reference to the next node
};
node *head;
int printList(node *traverse) {
if (traverse->next == NULL) {
return -1;
}
traverse=traverse->next;
printList(traverse);
cout << traverse->data << endl;
return 0;
}
int main() {
node *temp = NULL;
node *begin = NULL;
for (int i = 0; i < 10; i++) {
temp = new node;
temp->data = i;
if (begin == NULL) { …Run Code Online (Sandbox Code Playgroud) 当我尝试运行单元测试时,我收到此错误.整个错误是:
Undefined symbols for architecture i386:
"_CGImageRelease", referenced from:
_releaseImages in UIImage+animatedGIF.o
"_CGImageSourceCopyPropertiesAtIndex", referenced from:
_delayCentisecondsForImageAtIndex in UIImage+animatedGIF.o
"_CGImageSourceCreateImageAtIndex", referenced from:
_createImagesAndDelays in UIImage+animatedGIF.o
"_CGImageSourceCreateWithData", referenced from:
+[UIImage(animatedGIF) animatedImageWithAnimatedGIFData:] in UIImage+animatedGIF.o
"_CGImageSourceCreateWithURL", referenced from:
+[UIImage(animatedGIF) animatedImageWithAnimatedGIFURL:] in UIImage+animatedGIF.o
"_CGImageSourceGetCount", referenced from:
_animatedImageWithAnimatedGIFImageSource in UIImage+animatedGIF.o
"_kCGImagePropertyGIFDelayTime", referenced from:
_delayCentisecondsForImageAtIndex in UIImage+animatedGIF.o
"_kCGImagePropertyGIFDictionary", referenced from:
_delayCentisecondsForImageAtIndex in UIImage+animatedGIF.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)
我在这里做了所有的指示:http: …
在之前的XCode版本(4)中,我能够点击Xcode,它将拥有Source Control - > Repositories
现在,他们已将Source Control作为新的下拉菜单移动,但它没有存储库部分,我可以检查我的SVN并查看所有其他项目.
有没有办法打开存储库窗口?
我有一个问题.
在理论计算机科学方面,当我们分析算法时,如果算法初始化一个新的数据结构,那么我们认为数据结构是空间复杂性的一部分.
现在我对这部分不太确定.
假设我有一个数组,int我想通过使用int指针映射来映射它们.如
std::map<int*,int*> mymap;
for (int i = 1; i < arraySize; i++) {
mymap[&arr[i-1]]=&arr[i];
}
Run Code Online (Sandbox Code Playgroud)
如果这个算法没有使用指针,那么我们可以清楚地说它正在初始化一个大小为n的映射,因此空间复杂度是O(n),但是对于这种情况,我们使用指针的地方,空间复杂度会是多少这个算法?
我有一台服务器,我知道上面Informix安装了一个,但我不知道是谁安装的。有封闭源客户端连接到该服务器,但除了用户名和密码之外,我无法获得任何相关信息。我不知道如何连接它,我不知道它的端口号和服务器名称是什么。我已经下载SQuirreL了JDBC Informix驱动程序。
如何在不知道端口和服务器名称的情况下连接到 JDBC Informix 服务器?
我通过使用这个例子添加了一个偏好:http: //git.eclipse.org/c/platform/eclipse.platform.ui.git/plain/examples/org.eclipse.ui.examples.readmetool/Eclipse%20UI%20Examples %20Readme%20Tool /组织/蚀/ UI /示例/ readmetool /
有关实际参考,请参阅此页面:http: //git.eclipse.org/c/platform/eclipse.platform.ui.git/plain/examples/org.eclipse.ui.examples.readmetool/Eclipse%20UI%20Examples %20Readme%20Tool/org/eclipse/ui/examples/readmetool/ReadmePreferencePage.java)
我只添加了一个复选框来测试它,当我搜索首选项中的复选框中的任何单词时,我看不到我的视图即将出现,但如果我输入当前Eclipse有的东西,那么它出现(即我输入背景,我可以看到)在常规选项卡住并且是粗体).
我想我不知何故需要添加搜索关键字来指向当前页面(或其他东西).但我找不到如何添加,或导致此问题的原因.
那么如何在" 首选项"窗口中为我创建的首选项执行搜索?
我一直在寻找,我正在使用Micro C/OS II实时操作系统.除了编写嵌套循环之外,我找不到创建延迟的方法.有什么办法可以造成延迟吗?
我有一个Scrollview,它的属性在viewDidAppear中设置.现在,当我第一次到Scrollview时,没有任何问题.但是我有分配给UINavigationController的按钮.因此当我按下其中一个UINavigationController打开时,当我关闭导航控制器时,ScrollView无法正常恢复.它基本上将屏幕中心对齐为先前按下的按钮位置.因此,如果我尝试向上滚动它不会.
我试过在我的viewDidAppear中使用它:
scrollView.center = CGPointMake(scrollView.contentOffset.x, scrollView.contentOffset.y);
Run Code Online (Sandbox Code Playgroud)
哪个不太奏效.我怎么解决这个问题?我使用的是iOS6.1
c++ ×3
linked-list ×2
traversal ×2
xcode ×2
algorithm ×1
c ×1
dictionary ×1
eclipse ×1
embedded ×1
find ×1
informix ×1
ios ×1
java ×1
pointers ×1
preference ×1
python ×1
real-time ×1
repository ×1
target ×1
testing ×1
uiscrollview ×1
unit-testing ×1
xcode5 ×1