+ 3
Help Needed
Okay so a N number of boys are standing in a line organised by their serial numbers. But the 1st and 2nd boy in the line keep quarrelling and the 1st boy leaves and goes to the end of the line. This counts as 1 rotation. After R rotations, i need the serial number of the 1st and last boy in the line. I almost did it except it works for only the inputs 4, 1, 4. I need something that works no matter what the inputs are. https://code.sololearn.com/cz2R8I1iFzWy/?ref=app
6 odpowiedzi
+ 4
https://code.sololearn.com/chYP4X434oN2/?ref=app
+ 4
# number rotation please try it, i am not sure if i understand it right
import sys
try:
strt = int(input('enter start number: '))
end = int(input('enter end number')) + 1
rota = int(input('enter rotations:')) + 1
inp = [x for x in range(strt, end)]
if end - strt < 2:
print('No rotation possible, must have at least 2 pers.')
sys.exit()
for i in range(strt, rota):
inp = inp[1:len(inp)] + inp[0:1]
except:
print('Invalid input, please check!')
print(inp)
print(f"number '1' is at pos {inp.index(1)+1}")
print(f"number {end-1} is at pos {inp.index(end-1)+1}")
+ 3
Zinnur Hossain
Thats the Syntax of range. It excludes last value
+ 2
Zinnur Hossain
I made some little changes and comments
+ 1
Oma Falk That works, although it prints one less than the number of boys i want. Say, i want 5 boys so i put the last number as 5, but theres only 4 boys in the list in the output. Also, what does Assembly.pop(0) mean and do?
0
Oma Falk Okay i understand that now, but firstno was supposed to be the serial no. of the first boy and lastno was supposed to be the serial no. of the last boy, so even when the serial no. of the last boy is 4, why does it only go upto 3?