python - 如何在 Python 中打印来自 while 循环和 if else 的变量
问题描述
我从程序中得到的错误是未定义的变量。
*
# Python 3.9.4
# import sys
# print(sys.version)
SubjectT = input("Enter your subject: ")
Tutor_Name = input("Enter your name: ")
Iterate = int(input("How many students are there? "))
# Set counter
# create count for each student
Accumulate = 0
for i in range(Iterate): # It will run how many time based on Iterate input
Score = float(input("Enter score: "))
Counter = True
while Counter:
if 80 <= Score < 100:
Accumulate1 = Accumulate + 1
elif 80 > Score >= 65:
Accumulate2 = Accumulate + 1
elif 65 > Score >= 50:
Accumulate3 = Accumulate + 1
elif Score < 50:
Accumulate4 = Accumulate + 1
else:
print("The number is a negative value or incorrect")
Again = input("Enter yes for restarting again or if you want to exit the program please press anything: ")
if Again in ("y", "Y", "YES", "Yes", "yes"):
continue
else:
break
print(f"Subject title:", {SubjectT}, "\nTutor:", {Tutor_Name})
print("Grade", " Number of students")
print("A", "Students: ", Accumulate1)
print("B", "Students: ", Accumulate2)
print("C", "Students: ", Accumulate3)
print("D", "Students: ", Accumulate4)
这是我在 Stackoverflow 上的第一篇文章。请原谅我的任何不当内容。非常感谢。
解决方案
你说
Counter = True
没有迭代,因此它将无限期地运行。使用 while 循环,您需要设置一些约束。
推荐阅读
- python - 你能给我一个分享我的python程序的方法吗?
- reactjs - react setstate 在循环中无法正常工作
- java - 如何为我的 HTTP GET 方法的 URL 设置变量端点?
- arrays - 具有唯一元素的 np 数组行
- xamarin.android - 一个小图像在 ImageView 中拉伸,其尺寸大于主图像
- python - 使用 Pandas 中的查询从 SQL 表中删除记录
- python - 读取文件并尝试补全数据库中缺失的信息
- python - 在嵌套理解中使用海象运算符 := 的替代方法
- arrays - 如何使用 Json Extractor 从 Jmeter 中的嵌套 Json 中提取数据
- python - 如何在python中将平面列表转换为字典?