+ 1
Can i use this:in range(-100,100,0.1)
4 Respostas
+ 2
Range stepping requires an integral value.
Next time you have a doubt, try it out first 👍
+ 1
Ipang of course i tried but the majority of languages can do this. So i thought i done something wrong. Thank you!
+ 1
This comes close, but I'm seeing occasional repetition, maybe you can fine tune it further
n =- 100.0
for i in range( -100, 100, 1):
print( f'{n:.2f}' )
for j in range( 1, 10 ):
n += 0.1
print( f'{n:.2f}' )
+ 1
# Hi! With ’in’ you test if the number is in the range: it becomes True or False. But your step size is a problem, and floats is a source to round off ertors. So use range to build (for example) a list that includes all the numbers in the range:
# Is 11.7 in the range [10.0, 10.1, ...., 11.9]?
n = 11.7
l = [k/10 for k in range(100, 120)]
print(l)
print(n in l) # Is 11.7 in the range?
# If you don’t like long lists, you can just swap the [brackests] to (parentheses) to get generator onstead:
n2 = 10.3
l2 = (k/10 for k in range(100, 120))
print(l2)
print(n2 in l2) # Is 10.3 in the range?
# Using 0.1*k instead of k/10 will likely result in round off errors.
https://code.sololearn.com/cVMYh4OmHWER/?ref=app