Python中文
首页
教程
问答
标签
搜索
登录
注册
程序中跳过Python for循环
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我正在尝试编写一个python程序来发送问题并检查答案。它有一个while-True循环,当接收到应答时,该循环被中断。文件“播放器.txt“只包含一个数字,这个数字是当前可以回答问题的玩家数量。我遇到的问题是这里代码中的for循环:</p> <pre><code>while True: myfile = open("players.txt","r") print("File: players.txt OPENED") for i in range(int(myfile.read())): print("For Loop STARTED") ftp.retrbinary("RETR answer"+str(i+1)+".txt",open("answer"+str(i+1)+".txt","wb").write) myfile = open("answer"+str(i+1)+".txt") print("File: answer"+str(i+1)+".txt OPENED") if answer == myfile.read(): scores[i] = scores[i] + 1 print("Player",str(i+1),"got the correct answer first.") correctanswerfound = True print("No answer from player",str(i+1),"yet.") if correctanswerfound == True: correctanswerfound = False break print("No answer from player",str(i+1),"yet.") if correctanswerfound == True: correctanswerfound = False break </code></pre> <p>正在跳过。有人知道为什么要跳过它吗?有没有什么可以修正的。在</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p><code>.read</code>方法返回字符串中读取的字节。因此,当您尝试<code>int(myfile.read())</code>时,它将为以10为基数的int()提供一个无效的文本(这是通过使用我的文件.read())</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何在Excel中读取公式并将其转换为Python中的计算?
2 回答
如何在excel中读取嵌入的excel,并将嵌入文件中的信息存储在主excel文件中?
8 回答
如何在Excel中返回未知列长度的非空顶行列值?
9 回答
如何在excel中选择数据列?
1 回答
如何在Excel中通过脚本自动为一列中的所有单元格创建公共别名
1 回答
如何在excel中高效格式化范围AttributeError:“tuple”对象没有属性“fill”
1 回答
如何在excel单元格中编写python函数
2 回答
如何在excel单元格中自动执行此python代码?
6 回答
如何在excel工作表中创建具有相应值的新列
9 回答
如何在Excel工作表中复制条件为单元格颜色的python数据框?
5 回答
如何在Excel工作表中循环
5 回答
如何在excel工作表中打印嵌套词典?
8 回答
如何在excel工作表中绘制所有类的继承树?
4 回答
如何在Excel工作表中自动调整列宽?
2 回答
如何在excel工作表中追加并进一步处理
6 回答
如何在excel工作表之间进行更改?
10 回答
如何在excel或csv上获取selenium数据?
1 回答
如何在Excel或Python中将正确的值赋给正确的列
1 回答
如何在excel或python中提取单词周围的文本?
6 回答
如何在excel或python中转换来自Jira的3w 1d 4h的fromat数据?
9 回答