Feb-02-2018, 10:38 AM
Hey guys.
I'm pretty new to Python but not to statistics and general programming. I have a very specific problem that I can't seem to be able to solve. I posted 1 time before and figured it out but the general gist of my small script is that I am simulating someone randomly pressing ascii-characters until they randomly guess a defined string. Now I want to do a small calculation in the end where I convert the number of characters typed into amount of time used. The formula I've decided is this: (((((number_characters/4)/60)/60)/24)/365.25). My problem is, that I don't know how to use {:d} as a number to be calculated in a print-function. The full code is below, but here are the parts I can't figure out:
I do this:
I'm pretty new to Python but not to statistics and general programming. I have a very specific problem that I can't seem to be able to solve. I posted 1 time before and figured it out but the general gist of my small script is that I am simulating someone randomly pressing ascii-characters until they randomly guess a defined string. Now I want to do a small calculation in the end where I convert the number of characters typed into amount of time used. The formula I've decided is this: (((((number_characters/4)/60)/60)/24)/365.25). My problem is, that I don't know how to use {:d} as a number to be calculated in a print-function. The full code is below, but here are the parts I can't figure out:
I do this:
if iTries%10000 ==0 and iTries!=0: print("Tries: %d Best Score: %d Best Guess: %s" %(iTries, best.iBestScore, best.sBestGuess)) return best.sBestGuess, iTriesAnd then the regular script is:
def main(): print("Done! Found '{:s}' in {:d} tries.".format(*begin("fish"))) if __name__ == "__main__": main()But when I try to add the calculation, I thought I could do it directly in main like:
def main(): print("Done! Found '{:s}' in {:d} tries.".format(*begin("fish"))) print("The person used '{:d}((((({:d}/4)/60)/60)/24)/365.25)' years) if __name__ == "__main__": main()What did I do wrong?