python - 试图找出我的代码是如何出错的
问题描述
我是一个学习Python的初学者,写了以下代码。为了控制循环流程,我尝试使用变量“test”,但循环从未停止过。欣赏是否有任何想法。
test=False
while test==False:
a=input("Please enter an even number to make test True: ")
if int(a)%2==0:
test==True
print("test is now True")
else:
print("Please try again!")
解决方案
test=False
while test is False:
a=input("Please enter an even number to make test True: ")
if int(a) %2 == 0:
test = True
print("test is now True")
else:
print("Please try again!")
修正了 test == true,应该是 test = true :) 学习愉快
推荐阅读
- python - 尝试绘制列表中出现频率最高的 25 个单词并获得额外的撇号和逗号
- sign - 如何仅为一台计算机签署 Safari 扩展程序?
- html - 部分在 HTML 中重叠
- c - 未声明错误“信息”(在此函数中首次使用)
- php - php posgres网站,但无法通过表单插入数据
- python-3.x - 从 3d 体积数据中提取 40 mm 立方体
- python - ImageDataGenerator 没有将实际输出保存到磁盘
- ms-access - 月历开始和结束日期女士访问
- c++ - 使用不变量来确定二分搜索中的边界条件
- node.js - 使用 mocha、sinon 和 chai 运行测试时,res.status(...).json 不是函数