Python Forum
Python 3.6 to executable
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python 3.6 to executable
#5
Could you explain more in detail how I should do that then?
Here's the python code:
from time import time
import random
key=input("Press any key and then enter to start ... ")
while key!="":
    alphabet=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
    distribution=[0,0,1,6,26,52,85,122,140,140,126,101,75,52,32,20,10,6,3,2,1,1,0,0,0,0]
    word=""
    counter=0
    wordtype=""
    chance=0
    timeonbatteryseconds=0
    timeonACseconds=0
    runlengthcalculator=0
    x=0
    y=0
    timescounter=0
    howmanywords=0

    def howmany(wordlength):
        howmanywords=0
        if language=="dutch" or language=="Dutch" or language=="nl" or language=="NL" or language=="nederlands" or language=="Nederlands" or language=="Nl":
            file = open("DutchWords.txt", "r")
            for element in file.readlines():
                if len(str(element))==int(wordlength)+1:
                    howmanywords+=1
            return howmanywords
        if wordtype=="common":
            file = open("CommonEnglishWords.txt", "r")
            for element in file.readlines():
                if len(str(element))==int(wordlength)+1:
                    howmanywords+=1
            return howmanywords
        if wordtype=="all":
            file = open("AllEnglishWords.txt", "r")
            for element in file.readlines():
                if len(str(element))==int(wordlength)+1:
                    howmanywords+=1
            return howmanywords

    def isValid(word):
        if language=="dutch" or language=="Dutch" or language=="nl" or language=="NL" or language=="nederlands" or language=="Nederlands" or language=="Nl":
            file = open("DutchWords.txt", "r")
            if word in file.read():
                return True
            else:
                return False
        if wordtype=="common":
            file = open("CommonEnglishWords.txt", "r")
            if word in file.read():
                return True
            else:
                return False
        if wordtype=="all":
            file = open("AllEnglishWords.txt", "r")
            if word in file.read():
                return True
            else:
                return False


    language=input("What language do you wish to proceed in? (dutch/english) ")

    if language=="" or language=="choose" and language!="dutch" and language!="Dutch" and language!="nl" and language!="NL" and language!="nederlands" and language!="Nederlands" and language!="Nl" and language!="english" and language!="English" and language!="Eng" and language!="eng":
        decider=random.randint(0,1)
        if decider==0:
            language="English"
            print("I'm gonna go with English.")
        if decider==1:
            language="Dutch"
            print("Laten we nederlands nemen.")
        
    if language=="english" or language=="English" or language=="Eng" or language=="eng":
        wordtype=input("What words do you want to generate? (common/all) ")
        if wordtype=="choose" or wordtype=="":
            decider=random.randint(0,1)
            if decider==0:
                wordtype="common"
                print("Let's only generate common words.")
            if decider==1:
                wordtype="all"
                print("Let's generate all words!")
        wordlength=input("How many characters do you want the word to have? ")
    if language=="dutch" or language=="Dutch" or language=="nl" or language=="NL" or language=="nederlands" or language=="Nederlands" or language=="Nl":
        wordlength=input("Hoelang moet het woord zijn? ")
                
    if wordlength=="choose" or wordlength=="kies" or wordlength=="kies maar" or wordlength=="kies zelf" or wordlength=="goh kies maar zelf" or wordlength=="goh kies maar" or wordlength=="aan u de keuze" or wordlength=="":
        x=random.randint(0,999)
        wordlength=7
        if x==0:
            wordlength=1
        for element in distribution:
            if x in range(y+1,y+element):
                wordlength=timescounter
                break
            timescounter+=1
            y+=element
            
        chance=float(((howmany(wordlength))/(26**wordlength))*100)
        timeonbatteryseconds=float(((26**int(wordlength))*1.5)*(10**(-9)))
        timeonACseconds=float(((26**int(wordlength))*3.6)*(10**(-9)))
            
        if language=="dutch" or language=="Dutch" or language=="nl" or language=="NL" or language=="nederlands" or language=="Nederlands" or language=="Nl":
            print("Laten we "+str(wordlength)+" letters nemen.")
            print("De kans dat dit me lukt is "+str(chance)+"%, want er zijn "+str(howmany(wordlength))+" nederlandse woorden met "+str(wordlength)+" letters.")
            #print("Aan netstroom zou dit ongeveer "+str(timeonACseconds)+" seconden duren.")
            #print("Op batterijstroom duurt dit waarschijnlijk echter "+str(timeonbatteryseconds)+" seconden. Maar ondertussen al weer minder natuurlijk!")
            print("Aan het genereren...")
        if language=="english" or language=="English" or language=="Eng" or language=="eng":
            if wordtype=="common":
                print("The chance of me pulling this off is "+str(chance)+"%, as there are "+str(howmany(wordlength))+" common English words with "+str(wordlength)+" characters.")
            if wordtype=="all":
                print("The chance of me pulling this off is "+str(chance)+"%, as there are "+str(howmany(wordlength))+" English words with "+str(wordlength)+" characters.")
            print("I'm gonna go for "+str(wordlength)+" characters.")
            #print("On AC power, this should take around "+str(timeonACseconds)+" seconds.")
            #print("On battery power, this'll probably take "+str(timeonbatteryseconds)+" seconds. But now already a lot less of course!")
            print("Generating...")
    else:
        wordlength=int(wordlength)
        
        chance=float(((howmany(wordlength))/(26**wordlength))*100)
        timeonbatteryseconds=float((26**int(wordlength))/(1.5*(10**9)))
        timeonACseconds=float((26**int(wordlength))/(3.6*(10**9)))
        
        if language=="dutch" or language=="Dutch" or language=="nl" or language=="NL" or language=="nederlands" or language=="Nederlands" or language=="Nl":
            print("De kans dat dit me lukt is "+str(chance)+"%, want er zijn "+str(howmany(wordlength))+" nederlandse woorden met "+str(wordlength)+" letters.")
            #print("Aan netstroom zou dit ongeveer "+str(timeonACseconds)+" seconden duren.")
            #print("Op batterijstroom duurt dit waarschijnlijk echter "+str(timeonbatteryseconds)+" seconden. Maar ondertussen al weer minder natuurlijk!")
            print("Aan het genereren...")
        if language=="english" or language=="English" or language=="Eng" or language=="eng":
            if wordtype=="common":
                print("The chance of me pulling this off is "+str(chance)+"%, as there are "+str(howmany(wordlength))+" common English words with "+str(wordlength)+" characters.")
            if wordtype=="all":
                print("The chance of me pulling this off is "+str(chance)+"%, as there are "+str(howmany(wordlength))+" English words with "+str(wordlength)+" characters.")
            #print("On AC power, this should take around "+str(timeonACseconds)+" seconds.")
            #print("On battery power, this'll probably take "+str(timeonbatteryseconds)+" seconds. But now already a lot less of course!")
            print("Generating...")
            
    starttime=time()

    while counter<=wordlength:
        word=word+alphabet[random.randint(0,25)]
        
        if len(word)==wordlength:
            if isValid("\n"+word+"\n")==True:
                if language=="english" or language=="English" or language=="Eng" or language=="eng":
                    print("The generated word is: "+word)
                if language=="dutch" or language=="Dutch" or language=="nl" or language=="NL" or language=="nederlands" or language=="Nederlands" or language=="Nl":
                    print("Het gecreƫerde woord is: "+word)
            else:
                word=""
                counter=0
        counter=counter+1
        runlengthcalculator=runlengthcalculator+1
        
    endtime=time()
    timetaken=endtime-starttime
    if language=="dutch" or language=="Dutch" or language=="nl" or language=="NL" or language=="nederlands" or language=="Nederlands" or language=="Nl":
        print("Dit heeft ongeveer "+str(round(timetaken,2))+" seconden geduurd.")
        key=input("Druk op eender welke toets en dan enter om een ander woord te creƫren, druk enter om af te sluiten ... ")
    if language=="english" or language=="English" or language=="Eng" or language=="eng":
        print("This took around "+str(round(timetaken,2))+" seconds.")
        key=input("Press any key and then enter to generate another word, press enter to close ... ")
    counter=0
Reply


Messages In This Thread
Python 3.6 to executable - by DeGerlash - Jan-09-2018, 10:05 PM
RE: Python 3.6 to executable - by snippsat - Jan-09-2018, 11:21 PM
RE: Python 3.6 to executable - by DeGerlash - Jan-10-2018, 08:40 AM
RE: Python 3.6 to executable - by snippsat - Jan-10-2018, 12:34 PM
RE: Python 3.6 to executable - by DeGerlash - Jan-10-2018, 05:27 PM
RE: Python 3.6 to executable - by snippsat - Jan-10-2018, 06:12 PM
RE: Python 3.6 to executable - by DeGerlash - Jan-10-2018, 09:11 PM
RE: Python 3.6 to executable - by snippsat - Jan-10-2018, 09:26 PM
RE: Python 3.6 to executable - by DeGerlash - Jan-12-2018, 01:41 PM
RE: Python 3.6 to executable - by snippsat - Jan-12-2018, 02:26 PM
RE: Python 3.6 to executable - by DeGerlash - Jan-15-2018, 10:10 PM
RE: Python 3.6 to executable - by snippsat - Jan-15-2018, 10:21 PM
RE: Python 3.6 to executable - by DeGerlash - Jan-15-2018, 10:24 PM
RE: Python 3.6 to executable - by snippsat - Jan-15-2018, 10:34 PM
RE: Python 3.6 to executable - by DeGerlash - Jan-16-2018, 01:49 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Create Python "Executable" from PyCharm? Oliver 8 61,463 Jan-08-2018, 10:52 AM
Last Post: Oliver

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020