<file_sep># -*- coding: utf-8 -*-
"""
Created on Wed Jun  6 14:41:03 2018

@author: spanier
"""
import random
   # print random.randint(3, 9)
import math
#from myboolfuncs import 

    
   
def Reshuma(N):
    tup=()
    for i in range(N):
        T1= random.randint(3, 9)
        tup +=  (T1,)
    print(tup)
    return tup

def MyGuess(N1):
    myGuess=[]
    for j in range(N1):
         guess =  input("Try to guess the numbers between 1-9! :")
         myGuess.append(guess)
    for i in myGuess:
        print(i)
    return myGuess

def nihushTest(r,g,num):
    result=()
    success=0
    for i in range(num):
        if r[i]==g[i]:
            item=r[i]
            result= result+item
            success+=1
        else:
            result= result + ("X",)
    p= success/num
    percent= p*100
    print(result, end=" ")
    print (percent)
    return
    


while True:
     num = int(input("How many digits do you want to guess (press -1 to quit):"))
     if num == -1:
         break
     else:
         reshuma= Reshuma(num)
         guessList= MyGuess(num) 
         nihushTest(reshuma,guessList,num)<file_sep># -*- coding: utf-8 -*-
"""
Created on Wed Jun  6 14:04:12 2018

@author: spanier
"""

def dictionary(L):
    sumTuple=0
    sumList=0
    sumString=0
    sumInt=0
    sumFloat=0
    for item in L:
        if isinstance (item,tuple):
            sumTuple+=1
        if isinstance (item,list):
            sumList+=1
        if isinstance (item,str):
            sumString+=1
        if isinstance (item, int):
            sumInt+=1
        if isinstance (item, float):
            sumFloat+=1
    return {list : sumList, int : sumInt, float : sumFloat, str : sumString, tuple : sumTuple}<file_sep>"# Python-Structures" 
<file_sep># -*- coding: utf-8 -*-
"""
Spyder Editor

This is a temporary script file.
"""


def TOlist(L):
    lst=[]
    for item in L:
        if isinstance (item,tuple):
            for value in item:
                lst.append(value)
    #print(lst)
    return lst    
        
def ToTuple(T):
    tup=()
    for item in T:
        if isinstance (item,list):
               T1=tuple(item)
               tup= tup+T1
    #print(tup)
    return tup    

def listOfStrings(LS):
    L1=[]
    for item in LS:
        if isinstance (item,str):
            for value in item:
               if checkIfExist(LS, value):
                    L1.append(value)
    #print(L1)
    return L1  

def listOfNums(LN):
    L2=[]
    for item in LN:
        if isinstance (item, int or float):
            if checkIfExist(LN, item):
              L2.append(item)
    #print(L2)
    return L2

def checkIfExist(lst,val):
    checkList=TOlist(lst)
    checkTuple=ToTuple(lst)
    for i in checkList:
        if val==i:
            return False
    for j in checkTuple:
        if val==j:
            return False
        
    return True 
        
        
        
        
        
        
        
        
        
        
        
        
        
        <file_sep># -*- coding: utf-8 -*-
"""
Created on Mon Jun 11 15:59:04 2018

@author: spanier
"""
def replaceSimaneyPisuk(mahrozet):
    simaneyPisuk = ",.;:!?\t\n"
    newMahrozet = ""
    for c in mahrozet:
        if c in simaneyPisuk:
            newMahrozet += ' '
        else:
            newMahrozet += c
    return newMahrozet
#
def countWords(fileObj):
    D = dict([])
    for line in fileObj:
        wordsInLine = replaceSimaneyPisuk(line).split()
        for word in wordsInLine:
            if word not in D:
                D[word] = 1
            else:
                D[word] += 1
                return D
#
def prtWordCounts(D):
    prtLines = 1
    for word, count in D.items():
        if prtLines != 10:
            print(word, "was found", count, "times in the text.")
            prtLines += 1
        else:
            while True:
                ifBreak = input("Do you wish to stop printing? (Y, y, N or n)").upper()
                if ifBreak == 'Y':
                    print ('The printing of the word counts was stopped.')
                    return 
                elif ifBreak == 'N':
                    prtLines = 1
                    break
                #else:
                  #  continue
                else:
                    print ('All the word counts were printed')
                    return
#
#
# main program
#
if __name__ == "__main__":
    fileName = input("Please, enter the text file to be processed: ")
# in this program I use exception handling, but the students may
# write their program assuming that the text file exists
try:
    fileObj = open(fileName, "r")
    D = countWords(fileObj)
    prtWordCounts(D)
    fileObj.close()
except FileNotFoundError:
    print ("ERROR - file ", fileName, "not found!")
#