0
Is there a way to make a variable equal to all posative integers?
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'
+ 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?
0
Take a number and subtract the highest exponent of two that is not greater than said number Asman-H
0
Like 50-2^x with the equasion 2^x<50<2^(x+1) Asman-H