简体   繁体   中英

Typeerror in python with sum, list and range

Good morning, srs,

Why this result in error?

n = float(input("Origin value : "))
K = float(1)
while K <= n:
   P = sum(list(range((float(K)), float(n*K))))
   K*= 1.05
print(P, "and", K)

In this case appear:

    P = sum(list(range((float(K)), float(n*K))))
TypeError: 'float' object cannot be interpreted as an integer

Thank you, srs!

The range function wants an integer (you can't do something 1.1 times, right?). When you generate your range, decide whether you want to round the bounds up or down.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM