q12: Alternative solution
l=[] for i in range(1000,3001): t=[int(j)%2 for j in list(str(i))] tp=list(set(t)) if tp.count(1)==0: l.append(str(i)) print(','.join(l))
how about this?
a='' for i in range(1000,3001): if i%2==0: a=a+str(i) a=a+str(',') print(a) it works
a=[] for i in range(1000,3001): if i%2==0: a=a+[str(i)] print(','.join(a))
Is it ok OR can you want another one ?
You can try this
Result = [ i for in range(1000, 3001) if i%2 == 0] print(Result)
Hi, It returns syntax error because i is not declared there the below one return the output as expected
Result = [ i for i in range(1000, 3001) if i%2 == 0] print(Result)
http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail Virus-free. www.avg.com http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
On Sun, Sep 8, 2019 at 1:36 PM Manish-Ranjan [email protected] wrote:
You can try this
Result = [ i for in range(1000, 3001) if i%2 == 0] print(Result)
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/zhiwehu/Python-programming-exercises/issues/80?email_source=notifications&email_token=AMVU576A4X6JZEVFDTK7DVTQISXBRA5CNFSM4ICU6BL2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6FKM2A#issuecomment-529180264, or mute the thread https://github.com/notifications/unsubscribe-auth/AMVU577ZTG2QMGCS6IKN7NDQISXBRANCNFSM4ICU6BLQ .
Hi, i didn't get any type of error. you don't have to declare variable i .Range function always gives you integer but if you want a list of string values then you simply typecast int into string ( str(i) for i in range(1000, 3001) if i%2 == 0]