0

Is there a way to make a variable equal to all posative integers?

15th Nov 2019, 4:18 PM
pixel strength
pixel strength - avatar
4 Respostas
+ 3
You can alos use abs() function to test like this: a= -5 print('positive') if a-abs(a) == 0 else print('negative') # output: 'negative'
15th Nov 2019, 6:41 PM
Lothar
Lothar - avatar
+ 2
You can check, is a variable positive: if var > 0: do_smth You can use for, if you want to use positive numbers in range: for i in range(1, somevalue): do_smth_with_i You can use while loop, to prevent negative input: while True: a = int(input()) if a > 0: break Can you clarify, what you want exactly?
15th Nov 2019, 4:32 PM
Asman-H
Asman-H - avatar
0
Take a number and subtract the highest exponent of two that is not greater than said number Asman-H
15th Nov 2019, 4:33 PM
pixel strength
pixel strength - avatar
0
Like 50-2^x with the equasion 2^x<50<2^(x+1) Asman-H
15th Nov 2019, 5:54 PM
pixel strength
pixel strength - avatar