我希望循环将integers
添加到列表中,并在用户点击返回时break
。
我该如何设法做到这一点?
lstScore = []
count = 0
while count >= 0:
count = int(input("Enter a score :"))
if count != int:
break
elif:
lstScore.append(int(count))
答案 0 :(得分:0)
这应该对你有所帮助,为int转换错误添加了异常处理
public class WebService {
public static String devicelisting() {
Socket nsocket;
String response = null;
try {
nsocket = new Socket("192.168.1.1", 6666);
if (nsocket.isConnected()) {
JSONObject json = new JSONObject();
json.put("cmd", "request_get_file_list");
json.put("verification", "CVS");
Log.i("AsyncTask", "doInBackground: Creating socket");
// nsocket = new Socket();
OutputStreamWriter out = new OutputStreamWriter(nsocket.getOutputStream(), StandardCharsets.UTF_8);
out.write(json.toString());
Log.i("Webservice", "json.toString"+json.toString());
InputStream in = new BufferedInputStream(nsocket.getInputStream());
BufferedReader r = new BufferedReader(new InputStreamReader(in));
StringBuilder stringbuilder = new StringBuilder();
String line;
while ((line = r.readLine()) != null) {
stringbuilder.append(line);
Log.i("line", "line.line"+line);
}
response = stringbuilder.toString();
Log.i("Response", response);
}
else{
Log.i("Response", "not connected");
}
} catch (ProtocolException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return response;
}