If I want to do an Operator with the first number in range(any thing) with the first number in range(anything) and so on But not the first number in first range with the second or third number in the another range
5/17/2022 10:44:42 AM
ZIZO Abd alkawy17 Answers
New AnswerZIZO Abd alkawy a=range(1,4) b=range(5,8) for i in range(len(a)): for x in range(len(b)): if i==x: print(a[i]+b[x]) OR better πππ a=range(1,3) b=range(5,8) for i in range(len(a)) : print(a[i] + b[i]) I think this one you have studied
first you declare inputs as a list and use index for operations eg. x[2]+y[1], to add the 3rd number in the 1st range and the 2nd number in the 2nd range ,try by your own and if it is hard i will send short code.
ZIZO Abd alkawy, difficult to understand. please link your code here also provide an input / output sample
ZIZO Abd alkawy , nested for loops do not run in parallel. to achieve this we can use zip() function: for ra1, ra2 in zip(range(1,3), range(1,3)): print(ra1 + ra2)
ZIZO Abd alkawy , you don't need to make a function, just use zip() which is a built-in function providedfrom python
MULUKEN ADDIS a =[range(1,5)] b =[ range(1,5)] for i in range(len(a)),range(len(b)): print(a[0] + b[0]) I tried this but the code didn't run
TRY THIS! ZIZO Abd alkawy n=int(input("how many numbers do you want to add in the range\n") ) d=[] sum=0 for i in range(n) : d.append(int(input("write 1 number,and press enter\n"))) print (d) n=int(input("how many numbers do you want to add in the second range\n") ) f=[] sum=0 for i in range(n) : f.append(int(input("write 1 number,and press enter\n"))) print('the sum of the second number in the first range and the first number in the secon range is:\n') print (d[1]+f[0]) """you can Change the indexes!!! d[1] is the second number in the range f[0] is the first number in the range""" """hit an upvote if it is help ful"""
MULUKEN ADDIS there is a problem in line 8 or in my input I don't know Pls give me an input and check out the line 8 Thanks for your help
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message