Hi, today I tried to help with one of the request in Python tutor about trailing zeros -6days old. I don't know why my code is incrementing in number. Here is the code:
def factorial(): print("Here you will put your factorial") factVar=int(input("Please input what number to be factorial: \t")) TValue=0 for i in range(0,factVar+1): TValue+=i*i+1 print("Your total factorial: "+str(TValue)) return TValue def trailing_zeros(): value=factorial() dvdVal=1 divider=1 totalTrailingZeroes=0 while dvdVal !=0: try: answer=0 answer=int(value/5**(divider)) totalTrailingZeroes+=answer while answer !=0: if answer >0: answer=int(value/5**(divider+1)) newanswer=round(answer,1) totalTrailingZeroes+=newanswer elif answer <=0: dvdVal=0 print(str(TrailingZeroes)) except Exception: print("Sorry About that") trailing_zeros() Here is what I tried After ward ###And here is why I tried Afterwards def factorial(): print("Here you will put your factorial") factVar=int(input("Please input what number to be factorial: \t")) TValue=0 for i in range(0,factVar+1): TValue+=i*i+1 print("Your total factorial: "+str(TValue)) value=TValue dvdVal=1 divider=1 totalTrailingZeroes=0 answer=int(value/5**(divider)) totalTrailingZeroes+=answer newanswer=round(answer,1) while newanswer !=0: if newanswer >0: answer=int(value/(5**(divider+1))) newanswer=round(answer,1) totalTrailingZeroes+=newanswer print(str(totalTrailingZeroes)) else: newanswer=0 print(str(TrailingZeroes)) factorial() """ def trailing_zeros(): value=factorial() dvdVal=1 divider=1 totalTrailingZeroes=0 while dvdVal !=0: try: answer=0 answer=value/5**(divider) totalTrailingZeroes+=answer while answer !=0: if answer >0: answer=value/5**(divider+1) newanswer=round(answer,1) totalTrailingZeroes+=newanswer elif answer <=0: dvdVal=0 print(str(TrailingZeroes)) except Exception: print("Sorry About that") trailing_zeros() """ _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor