0
Trying to do binarization convert numbers that are <= threshold
im trying to write a code that converts nums that are <= threshold. and returns the value if its great its 1 if its less its a zero!! ** can someone help me please??**
73 odpowiedzi
0
@madhukar this is what i got when i tried to combine the both
threshold = int(input('Please Input Threshold Number Value: '))
x = int(input(' Please Input x Number Value: '))
y = int(input(' Please Input y Number Value: '))
for i in range(x):
if(i >= threshold):
x = 0
else:
x = 1
for i in range(y):
if(i >= threshold):
Y = 0
else:
Y = 1
print('x =', x)
print('y =', y)
This is the output i got
```python
Please Input Threshold Number Value: 3
Please Input x Number Value: 2
Please Input y Number Value: 4
x = 1
y = 4
+ 1
you should explain your question/request more, like giving exemples ...
😅
and the programming language your using
+ 1
Yes thats what i mean thanx for acknowledging me
+ 1
Wow this is way too complicated for me to understand lolz i am a beginner lolz but i appreciate you time for doing this to assist me
+ 1
you know I won't teach you pyhton
...
I'm not even that good at python
I just want to tell you how for-loops work (in a simple way) since they are quite important.
+ 1
sum starts with 0
with every iteration of the for loop sum inreases by 1
in the end sum is divided by i which will have the value of end
the range function accepts a start and an end (if only one argument is given start is 0 and end is the given number; you can even add an third argument for the iteration-step...)
, anyway the range starts with the starting number and gets incremented by 1 until it is equal or bigger than the end
this for-loop is very unnessecary since "(end + 1 - start) / end" does exactly the same...
+ 1
the for-loop just counts from your start up to your end number and (probably, since that makes more sense) adds them together.
if you would look at the value of sum every time it changed it would look like this (start: 0, end: 3):
sum: 0,
sum: 1,
sum: 3
the third time won't be executed since the range function only counts up until it reaches the end number and stops there.
In the end i will have the value of end.
+ 1
The thing is you have written:
for i in range(start, end):
sum += 1
-> this can be easily replaced by end - start
But more sense makes:
for i in range(start, end):
sum += i
-> this can't be rewritten that easily (unless there are special cases like start always equals 0 or sth. like that...)
0
Lolz Sorry budz i really new to python and not sure where to start but i trying to learn with a simple problem. Some things i get and well the rest i ask pros to explain until i get it
0
Program language is python and what i am trying to achieve is to get binary 1s and 0s from a specific threshold thats best i can explain it
0
Can you help me please?
0
do you mean if a number is less than an other number return/print 0 otherwise return/print 1?
if yes that would be something like this:
a = int(input("your number"))
threshold = 10
if a <= threshold:
print("0")
else:
print("1")
happy coding
0
Not sure if it will work give me a sec please feeding these animals
0
Thanx mate it did
0
I have a question please?
How do i handle a print for two numbers for the same code
Lets say i have a threshold 5 and I'm entering two inputs lets say one input is 3 and the other is 6
How do i get the code to represent printing a = 1 and b = 0 or vice versa based on the input value from the user?
this is what i have as an example which is NOT functional its works but it doesn't handle this situation!
a = int(input("your number"))
b = int(input("your number"))
threshold = 4
if a <= threshold and b <= threshold:
print("a = 0")
print("b = 0")
else:
print("a = 1")
print("b = 1")
thanx in advance for assisting me!
0
Ohhh can this be represented by 2 FOR loops one checking the rows and one checking the columns? if so show me please would greatly appreciate it!
0
I have this:
x = input(" Please enter your x number value: ")
y = input(" Please enter your y number value: ")
threshold = 4
for x in range(x):
x <= threshold
print("x = 1")
if x in range(x) >= threshold:
print("x = 0")
for y in range(y):
y <= threshold
print("y = 1")
if y in range(y) >= threshold:
print("y = 0")
i am.not sure where my errors are please guide me
0
are you trying ro do this?
X = int(input(" Please enter your x number value: "))
Y = int(input(" Please enter your y number value: "))
threshold = 4
for x in range(X):
print("x = " + str(x))
if x <= threshold:
print("0")
else:
print("1")
for y in range(Y):
print("y = " + str(y))
if y <= threshold:
print("0")
else:
print("1")
0
Let me input this now one sec please
0
if not explain more clearly please