+ 1
How one go about this?
Write a program which will find all such numbers which are divisible by 7 but are not a multiple of 5 between 2000 and 3200 (both included) the numbers obtained should be printed in a comma separated sequence on a single line from largest to the smallest
6 ответов
0
nums=[i for i in range(2000,3200) if i%7==0]
nums=[i for i in nums if i%5!=0]
nums=nums[::-1]
for i in nums:
print(i, end=',')
+ 4
print([i for i in range(3200, 1999, -1) if ((i % 7 == 0) and (i % 5 != 0))])
Sorry for getting straight to it, though... :)
+ 1
Well, I would have done:
print(', '.join(sorted([k for k in range(2000, 3201) if not k % 7 and k % 5]))
but that is not a really pretty code...
0
With a given integral number n, write a program to generate a dictionary that contains (I, i*I) such that is an integral number between 1 and n (both included) and the program should print dictionary
0
come on now, we can't do all your homework
0
and Kuba answer is the best answer. my code does the same thing his does, but his does it more efficiently. Might as well point the best answer nod his way. If I had saw he posted a solution I wouldn't have bothered.
altho, the request was to print the numbers in a single line separated by commas. I did get him there, he just printed the list. Victory is mine! Jk, Kuba is much better at this than I am. He often makes me a better programmer simply by seeing how he tackles a problem differently than I