我的作业是编写一个将十进制转换为二进制的程序,我确实完成了编码,但是在接受用户输入后,它没有打印出二进制+垃圾值,我很确定我的算法是正确的,但是我尝试修复,但是它仍然无法正常工作。
这是我的代码
# Assume that the user inputs this when prompted ->
user_input1 = "100000 23010915"
user_books = "496 383 251 827 272 703 514 147 36 343 234 538 817 770 443 664 349 33 34 627 275 590 608 713 568 496 766 718 106 193 259 138 727 126 760 646 204 764 276 79 68 488 782 475 649 619 171 632 228 669 683 800 53 65 115 400 212 373 764 54 631 29..."
def books():
input1 = list(input("Enter input1").split()) # See above (user_input1)
books = list(input("Enter books").split()) # See above (user_books)
numBooks = int(input1[0])
minutes = int(input1[1])
books.append(minutes*10)
counterList = 0
for i in range(len(books)):
counter = 0
counter2 = 0
for j in range(i,len(books)):
if (counter + int(books[j]) > minutes:
break
else:
counter += int(books[j])
counter2 += 1
#print(i,j,counter,counter2,books)
if counter2 > counterList:
counterList = counter2
print(counterList)
books()