I wanted to solve the problem, it turned out correctly but not as it should. Problem: Print all the numbers on the segment from a to b that give the remainder of c when divided by d. If such numbers do not exist, then you do not need to display anything. Input: 2 5 0 2. In Output: 2 4. In general, my code:
a= int (input ()) b= int (input ()) c= int (input ()) d= int (input ()) sum= 0 for i in range (a, b + 1): if i% d== c: print (i)
In output, I got: 2 and below 4, but it should be so that 2 and 4 are on the same line and with a space. How to do it? Whoever says the answer will give a back massage
Answer # 1
do you need this?
a, b, c, d= map (int, input (). split ()) print (* [i for i in range (a, b + 1) if i% d== c])
here input and output will be in 1 line
Answer # 2
Give print a space as the end of the line (instead of a line feed).
for i in range (a, b + 1): if i% d== c: print (i, end= "") print ()
- Python does not see pip3 modules
- python : Determine the length of the longest string consisting of only characters A, B and C
- python : Find k numbers closest to a given value in an ordered array
- python : how can one split each word in a two dimensional array into separate characters
- python : The code works, but the execution time limit is exceeded
- How to count the number of specific letters in a word generated by a loop -Python
- python : How to validate user input in a telegram bot?
- python : How can I find the words that are given in the second array in the first array
- python : Why do we need Dekstop PyQt5 window type?