#can someone help me fix dis, it keeps printing the lowercase x's

1 messages · Page 1 of 1 (latest)

floral nest
#

Are your sure it is a lowercase x and not an uppercase X

tulip abyss
#

ye its lowercase

#

sry

#

i alr fixed it

#

@floral nest r u a python proffesional

#

or expeireinced

floral nest
#

Not a professional

tulip abyss
#

r u moderate?

floral nest
#

But i believe i have above intermediate level experience

tulip abyss
#

ok

#

good

#

so can u help me on this?

floral nest
tulip abyss
#
a = input()
arr = []
i = 0 
while i<= len(arr)-1 and a[i] % 2 in ('0', '1', '3', '5'):
    a[i] = int(a[i])
    arr.append(a[i])
print(arr)```
floral nest
#

Mhm what's wrong with that

tulip abyss
#

idk

floral nest
#

Well what do you need help with

tulip abyss
#

it only print []

floral nest
#

You might want to use a for loop

tulip abyss
#

i know

#

but i want to use while loops

#

cuz i can do for lloops easily

floral nest
#

Oh

#

Any number mod 2 will return only 0 or 1

tulip abyss
#

what

floral nest
#

I hope you know what % operator is

#

It gives the remainder after division

tulip abyss
#

ye

#
a = int(input())
arr = []
i = 0 
while i<= len(arr)-1 and int(a[i]) % 2 == 0 in (1,2,3,4,5):
    arr.append(a[i])
print(arr)```
#

but it doesnt append anything

floral nest
#

Ok wait

#

You are now comparing int(a[i]) % 2 with 0
That will return either True or False

You are then checking if True or False is in (1,2,3,4,5)

tulip abyss
#

what?

floral nest
#

int(a[i]) % 2 == 0 in (1,2,3,4,5)

tulip abyss
#

ye

floral nest
#

int(a[i]) % 2 == 0
This returns True or False

tulip abyss
#

ye

floral nest
#

How will that be in (1,2,3,4,5)

tulip abyss
#

idk

floral nest
#

Use parenthesis to make it more clean

tulip abyss
#

where tho

floral nest
#

Also you never increment i

tulip abyss
#

?

#

ohhh

floral nest
#

It's not a for loop, you have to increase the value of i or it will always stay 0

tulip abyss
#

ok

#

done

#

the conditions r alr true so it skips it

#

i did this

#
arr = []
i = 0 
while i<= len(arr)-1 and a[i] % 2 != 1:
    arr.append(a[i])
    i += 1
print(arr)```
#

if the remainder thing is 1 it skips

floral nest
#

Also int is not sliceable like that

#

Don't convert input to int

#

Let it stay str

#

Convert to int during the while loop logic and during appending

tulip abyss
#

it work tho

#

cuz u can divide a string by a inteter

floral nest
#

It shouldn't cuz you convert to int

#

But

#

.itworks

tawdry onyxBOT
tulip abyss
#

bruh

#

@floral nest

floral nest
#

What?

#

You said it works

tulip abyss
#

@floral nest

#

help me on this

#
a = input()
arr = []
i = 0
while i<= len(a)-1 and int(a[i]) % 2 == 0:
    arr.append(int(a[i]))
    i += 1
print(arr)```
tawdry onyxBOT
#

Saying it doesn't work or asking what's wrong with this code is not helpful for yourself or others.
Describe what you expect and/or tried (with your code), and what isn't going right.
Please provide any errors you get for optimal assistance.

floral nest
#

What do you need help with

tulip abyss
#

i want it to append even numbers

#

for example

#

input is 24680

#

the output

#

is 24680

#

0 is not even

#

but it still prints it

floral nest
#

According to python, 0 is even

tulip abyss
#

ok

#

so hiow should i fix it

floral nest
#

Check if it is not equal to 0 before doing % 2

tulip abyss
#

how

floral nest
#

int(a[i]) != 0

#

Yk your loop will break the moment it faces an odd number

tulip abyss
#

ok

#

but it still prints it

#

eh

#

if input is 65420

#

its supposed to only print 6

#

cuz its the first and even number

#

cuz teh next interger is odd

floral nest
#

Hmm

tulip abyss
#

ehh

tulip abyss
#

done it