0

我的目标是制作一个程序,它接受输入 (Battery_Capacity) 并最终吐出 (New_Battery_Capacity) 列表和最终达到最大容量 80 所需的 (Cycle) 数。

Cycle = range (160)
Charger_Rate = 0.5 * Cycle
Battery_Capacity = float(raw_input("Enter Current Capacity:"))
New_Battery_Capacity = Battery_Capacity + Charger_Rate

if Battery_Capacity < 0:
    print 'Battery Reading Malfunction (Negative Reading)'

elif Battery_Capacity > 80:
    print 'Battery Reading Malfunction (Overcharged)'

elif float(Battery_Capacity) % 0.5 !=0:
    print 'Battery Malfunction (Charges Only 0.5 Interval)'

while Battery_Capacity >= 0 and Battery_Capacity < 80:
    print New_Battery_Capacity 

我想知道为什么我的 Cycle = range(160) 在我的程序中不起作用?

4

1 回答 1

0

Your first problem is that you have the first two lines in the wrong order. You need a "Cycle" variable to exist before you can use it.

You'll still get an error when you swap them, though. You can't multiply a list by a float. A list comprehension is more what you want:

Charger_Rate = [i * .5 for i in Cycle]

As far as I can tell, the range(160) part is fine.

于 2012-11-26T23:02:48.490 回答