这里我有一个函数
def celToFah(x):
ftemps = []
for i in x:
ftemps.append((9/5 * i) + 32)
return ftemps
Run Code Online (Sandbox Code Playgroud)
我在列表理解中称之为它。
ctemps = [17, 22, 18, 19]
ftemps = [celToFah(c) for c in ctemps]
Run Code Online (Sandbox Code Playgroud)
出现以下错误
“int”对象不可迭代
为什么我会收到错误消息?
我正在开发一个开源项目(https://github.com/google/science-journal/tree/master/OpenScienceJournal)。通过这个应用程序,我可以记录一个实验。记录的实验以 .proto 扩展名存储。我尝试编译它们来生成类但失败了。
有什么办法可以打开这种文件吗?
我试图打印"偶数"或不打印列表理解,但我得到一个错误.
myNames = ['A','BB','CCC','DDDD']
myList3 = [ 'even' if x%2==0 else 'nope' for x in myNames]
Error: TypeError: not all arguments converted during string formatting
Run Code Online (Sandbox Code Playgroud)
它背后的原因是什么?
所以我很困惑,需要一个建议.在Java中,我可以实现自己的Stack,或者我可以使用java.util提供的Stack.
手册:
public class stack {
private int maxSize; //max size of stack
private char[] stackArray;
private int top; //index poistion of last element
public stack(int size){
this.maxSize=size;
this.stackArray=new char[maxSize];
this.top=-1; //
}
public void push(char j){
if (isFull()) {
System.out.println("SORRY I CANT PUSH MORE");
}else{
top++;
stackArray[top]=j;
}
}
public char pop(){
if(isEmpty()){
System.out.println("Sorry I cant pop more!");
return '0';
}else{
int oldTop=top;
top--;
return stackArray[oldTop];
}
}
public char peek(){
if(!isEmpty()) {
return stackArray[top];
}
}
public boolean …Run Code Online (Sandbox Code Playgroud)