[Tutor] Advise with coding
Hi I have just started Com Sci in Uni and I am new to coding. I feel pretty inadequate as I am really struggling with the latest tasks. Most of the work is self-directed learning so we need to figure it out ourselves but I am running out of time. Is it possible someone on here can advise me where I am going wrong. Many thanks in anticipation T ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Code for python game
Im in the middle of designing a game in python, im quite new to using it and am struggling with a certain bit of code. I want to have a function that will ignore certain words that i have specified in a dictionary. I have tried so many different types of code but can't seem to return just the keywords i want. the dictionary is called skip_words and has about 20 different strings in. so far i came up with: def filter_words(words, skip_words): word = words.strip(skip_words) return word The function should read an input such as help me please and filter out the words "please" and "me" as they are in the dictionary and just return the word help as the input. >>>filter_words(["help", "me", "please"], ["me", "please"]) ['help'] That doesn't work but i just assume it is a very simple bit of code. any suggestions of a way that works? Thanks:) T ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Code not working advise pls
Hi, I want to write a function that will calculate and return the sum of the n highest value in a list a. Also, when n is less than 0, the answer should be zero, and if n is greater than the number of elements in the list, all elements should be included in the sum. In addition i want to write the code in a function with only one line of code in it. So far I have:- def sumHighest(a, n): lambda a, n : sum(a[:n]) This doesn't work but i want to use lambda and the slice in the function. An appropriate test would be:- input - sumHighest([1,2,3,4], 2) output - 7 Where am I going wrong? Thanks T. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Theory of computation non-emptiness
Hi there, I've been working on code that takes a text file that represents a specific Deterministic Finite Automata. The text files are set up in a specific way so that line 1 specifies the number of states. Line 2 specifies the states (i.e., just a list of the names of the states, separated by spaces). Line 3 specifies the size of the alphabet. Line 4 specifies the alphabet. Lines 5-7 give the transition function, each row corresponding to a state (in order specified on line 2) and each column corresponding to a symbol from the alphabet (in order specified on line 4). Line 8 specifies the start state. Line 9 specifies the number of final/accept states. Line 10 specifies the final states. I have already constructed some functions but next I want to construct a function determining, for any DFA M, whether or not L(M) = 0 i.e., whether or not there exists at least one string that is accepted by M. if the language If L(M) = 0 then I want “language empty” printed. If L(M) != 0; then i need to print “language non-empty - accepted”, where is replaced by some string that is accepted by M. I wanted to use breath first search in order to determine the existence of a path. Code below is all I've done so far but i'm struggling to find a way in which to link the states with the transitions in the text file. hope you can give me some direction and advice. def NonEmptiness(dic): dic = openTextFile(dic) #print(dic['states'].split()) theString = "" visited = [] queue = dic['states'].split() newStates = dic['states'] newStatesFinal = re.sub(' ','', newStates) newAplhabet = re.sub(' ','', dic['alphabet']) #print(dic['finalStates'][2]) print(newStatesFinal) #print(newStatesFinal[0]) while queue: currentState = queue.pop(0) visited.append(currentState) #print(visited) for a in newAplhabet: if (currentState, a) == (newStatesFinal[0], newAplhabet[0]): if dic['transitionStates'][0][0] != dic['finalStates'][0] or dic['finalStates'][2]: theString + a else: ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor