woooee 814 Nearly a Posting Maven

Use partial to pass something to the function, and the function will do something based on the value. This example prints what was passed to the function. Note that the Python Style Guide suggests function names should be lower case letters and underscores https://www.python.org/dev/peps/pep-0008/

root = tkinter.Tk()
root.geometry("200x300")
##buttons=range(10)
button_list=[]

def get_next(button_num):
    print("button number =", button_num)
    ## change the color of the button pressed to show how the list works
    button_list[button_num].config(bg="lightblue")

for num in range(10):
    btn=tkinter.Button(root, text="Button %d" % (num),
                       command=partial(get_next, num))
    btn.pack(side=tkinter.TOP)
    ## save a reference to the button so it can be used in get_next
    ## the button number corresponds to the offset in the list
    button_list.append(btn)

root.mainloop()
woooee 814 Nearly a Posting Maven

if not read_file:This statement is executed when bytes1 is found at the beginning of the file, offset/read_file==0). Use instead

      with open("foundhex.txt", "a") as found1:
          while True:
              read_file = bytearray(binaryfile.read(1024))
              if len(read_file):
                  find_bytes1 = read_file.find(bytes1, 0)
                  if fine_bytes1 != -1:
                      found1.write("Found 41646F626520 at : " + str(find_bytes1) + "\n")
              else:
                  break

Also this statement find_bytes1 = read_file.find(bytes1, 0)
starts at the beginning every time, so you are finding only the first sting and not any subsequent strings. Finally, for this statement read_file = bytearray(binaryfile.read(1024))
what happens if half of bytes1 is in one read, and half is in the next read?

woooee 814 Nearly a Posting Maven

You ignore spaces in the encoded message and insert a space at the appropriate number, ie. is in "key".

def decode(message, key):
    output=[]
    for ctr, ltr in enumerate(message):
        if ctr in key:
            output.append(" ")
        if ltr != " ":
            output.append(ltr)
    print "".join(output)

decode("HELLO WORLDT HISIS SOC OOL", [5, 11, 16, 19, 21])
woooee 814 Nearly a Posting Maven

Good point. Am assuming from "lastnight" that titles don't contain spaces. And if they do, the concept is still the same.

woooee 814 Nearly a Posting Maven

You split them and add a newline so they are on new lines. We don't know what type of variable favorite_movies is so there is no way to give an exact answer, but it is something along the same lines as

favorite_movies="spiderman lastnight matrix"
print favorite_movies
print "\n".join(favorite_movies.split())
woooee 814 Nearly a Posting Maven

First you have to define the limits of the character set. Are you using English/ASCII as other character sets have an extended range?

Do you want to encode special characters as well, @. ?. $ etc.

For your purposes, ASCII goes from decmal 32, space, through decimal 126, ~.

You can ask for an input from the user to get the offset. After the offset is applied, you then have to test if the resulting decimal value is < 32 or > 126 (for ASCII) depending on if it is encrypting or decrypting, and asjust accordingly. If it is < 32 then you possibly want to increase it by 95, which is the range of decimals used in the above example, 32...126.

Use the code tag in the header to paste your code here. It is not a good idea for us to go to some other site provided by a new poster as it can contain spam or worse.

Also, see "String to Integer" for typecasting the input string into an integer http://en.wikibooks.org/wiki/Non-Programmer's_Tutorial_for_Python_2.6/Revenge_of_the_Strings

second is that I dont know if I should be using a while loop there

Don't know what "there" means, but generally a for loop is used if you mean traverse the string
for character in input_string:

woooee 814 Nearly a Posting Maven

To execute a string you can use subprocess.call("string to execute", shell=True) See Doug Hellmann's subprocess explanation for additional info http://pymotw.com/2/subprocess/index.html#module-subprocess

woooee 814 Nearly a Posting Maven
for elem in self.programs_button:

That statement is not in the code you posted.

woooee 814 Nearly a Posting Maven

using main() is a waste as it is the same thing as putting it under if __name__ etc. Instructors use it to teach students about functions, and always use the same name so as not to confuse them. For "real programmers" each function has a specific function (makes sense) and has a descriptive name that says something about what the function does. Obviously main() is neither of these. And it is frustrating for debugging a progam when you go to the bottom to see what tests, etc. there are, and then find a main(), which means you now have to search through the program for it instead.

woooee 814 Nearly a Posting Maven

don't work this: bg_fon2 = PhotoImage(file='2.GIF')

We have no idea what that means. Is it displaying upside down, or cropped, bad colors, etc.

woooee 814 Nearly a Posting Maven

Send the list named matches to the function id_generator. If the element in the list equals "?" then generate a random letter. If not then append the letter from matches to the list to be returned. You don't want to update matches because you want it to remain as the control list, although you could copy it and update the copy but read how to copy from the link below if you do this as you can not just use a=b.. Traversing a list http://www.greenteapress.com/thinkpython/html/thinkpython011.html#toc108

woooee 814 Nearly a Posting Maven

It means check those other forums before answering, or we may be wasting our time answering a question that has already been answered elsewhere. We are volunteers and have limited time to spend.

In your particular case, you posted again that it does not change players, which I addressed with a hint in the first response. This implies that you are not reading our responses. Not reading the responses usually means that are we wasting our time because the OP is just looking for someone to code it for them instead of figuring it out for themselves, so isn't reading, just waiting for code that they can copy and paste.

woooee 814 Nearly a Posting Maven
woooee 814 Nearly a Posting Maven

You start with a list full of ? and replace each ? with a letter when guessed correctly.

## assumes both words are the same length

def display_matches(matches, test_word, sample_word):
    """     H?L?          HELP
            HEL?          HELP
            HELP          HELP
    """
    for ctr in range(len(test_word)):
        if test_word[ctr] == sample_word[ctr]:
            matches[ctr] = test_word[ctr]
    print "%s   %s  %s" % ("".join(matches), sample_word, test_word)
    return matches

test_word="HALE"
sample_word="HELP"
matches = ["?" for ctr in range(len(sample_word))]

matches=display_matches(matches, test_word, sample_word)
matches=display_matches(matches, "WXYZ", sample_word)
matches=display_matches(matches, "KEEN", sample_word)
matches=display_matches(matches, "HERO", sample_word)
matches=display_matches(matches, "STOP", sample_word)

""" results
H?L?   HELP  HALE
H?L?   HELP  WXYZ
HEL?   HELP  KEEN
HEL?   HELP  HERO
HELP   HELP  STOP
"""
woooee 814 Nearly a Posting Maven

second it does not give me messages for when a one is rolled or 2 is rolled

Do you mean one or two dice are rolled, or the dice rolled total one or two

nor does it go on to the next players turn like its suppose too

The function game() always assigns zero to player

I added one line as the previous roll was covering up the current roll

canvas.delete(ALL)  ## remove all items

and modified another as you were calling the function incorrectly

button1 = Button(master, text = "continue", command=game)

Complete code, modified, and if this does not do it, post back

from tkinter import*
from functools import partial

master=Tk()
canvas = Canvas(master, width = 300, height = 200);
canvas.pack();
from random import randint
#### Dice
def draw(rolled,rolled2):
    dice = [rolled,rolled2]
    for i in range(2):
        canvas.create_rectangle(5+195*i,50,105+195*i,150)
        if dice[i] == 1:
            canvas.create_oval(45+195*i,85,65+195*i,105, fill="black")
        elif dice[i] == 2:
            canvas.create_oval(12+195*i,52,32+195*i,72, fill="black")
            canvas.create_oval(82+195*i,122,102+195*i,142, fill="black")
        elif dice[i] == 3:
            canvas.create_oval(45+195*i,85,65+195*i,105, fill="black")
            canvas.create_oval(12+195*i,52,32+195*i,72, fill="black")
            canvas.create_oval(82+195*i,122,102+195*i,142, fill="black")
        elif dice[i] == 4:
            canvas.create_oval(12+195*i,52,32+195*i,72, fill="black")
            canvas.create_oval(82+195*i,122,102+195*i,142, fill="black")
            canvas.create_oval(12+195*i,122,32+195*i,142, fill="black")
            canvas.create_oval(82+195*i,52,102+195*i,72, fill="black")
        elif dice[i] == 5:
            canvas.create_oval(45+195*i,85,65+195*i,105, fill="black")
            canvas.create_oval(12+195*i,52,32+195*i,72, fill="black")
            canvas.create_oval(82+195*i,122,102+195*i,142, fill="black")
            canvas.create_oval(12+195*i,122,32+195*i,142, fill="black")
            canvas.create_oval(82+195*i,52,102+195*i,72, fill="black")
        elif dice[i] == 6:
            canvas.create_oval(12+195*i,52,32+195*i,72, fill="black")
            canvas.create_oval(82+195*i,122,102+195*i,142, fill="black")
            canvas.create_oval(12+195*i,122,32+195*i,142, fill="black")
            canvas.create_oval(82+195*i,52,102+195*i,72, fill="black")
            canvas.create_oval(47+195*i,52,67+195*i,72, fill="black")
            canvas.create_oval(47+195*i,122,67+195*i,142, fill="black")

    button1 = Button(master, text = "continue", command=game)
    button1.configure(width = 10, activebackground = "#33B5E5", relief = FLAT)
    button1_window = canvas.create_window(10, 180, anchor=SW, window=button1)


#####game    
def game():
    playercount = 2
    maxscore = 100
    safescore = [0] * playercount
    player …
woooee 814 Nearly a Posting Maven

You can use he same variable for the number of spaces to print, see below. If you want to print a total of 40 stars, I can't tell from your code and you didn't explain

empty_spaces=0
one_side=7 # stars
stars_side=0
incr=1
stars_printed=0
while stars_printed < 40:
    print "%s*" % (" "*empty_spaces)
    stars_printed += 1
    empty_spaces += incr
    stars_side += 1

    ## change direction every "one_side" stars
    if stars_side >= one_side:
        stars_side=0
        if incr == 1:
            incr = -1
            print "testing: incr changed to minus one"
        else:
            incr = 1
            print "testing: incr changed to plus one"
woooee 814 Nearly a Posting Maven

Print the variable, url, in the funtion to see if your title is correct or not.

woooee 814 Nearly a Posting Maven

You would have to use multiprocessing for the timer since the program is doing two things,
1. getting the answer
2. moving on/killing the question's process after 30 seconds whether the question has or has not been answered. Multiprocessing takes a little fiddling to get the input in a thread since a process does not use the same input stream as the non-in-a-process code, and you might also want to communicate to/from the thread with a Manager which is another thing to be learned.`

You could also use Tkinter (probably a better choice), which has a built in "after" method. Tkinter would also enable the user to click a button when finished instead of waiting for the 30 seconds to expire.

""" multiprocessing example
"""

import time
from multiprocessing import Process
import os
import sys

class AskQuestions():
   def __init__(self):
      self.answer=None
      self.correct_answers = 0

   def test_q(self, question, fileno):
      self.answer=None
      ## necessary to get input to work
      sys.stdin = os.fdopen(fileno)  #open stdin in this process
      print "\n\n", question
      self.answer = input("What is your answer? ")
      if self.answer:
          print "     Correct", self.answer

if __name__ == '__main__':
   AQ=AskQuestions()

   for question in ["The First Thing", "Second", "Last and Least"]:
       fn = sys.stdin.fileno()
       p = Process(target=AQ.test_q, args=(question, fn))
       p.start()
       ## sleep for 10 seconds and terminate
       time.sleep(10.0)
       p.terminate()
woooee 814 Nearly a Posting Maven

You can also eliminate some of the redundancy when printing the hangman

def print_hangman(turn):
    print("turn=%d" % (turn))
    if turn >= 1:
        print(' |')
    if turn >= 2:
        print(' O')
    if turn >= 3:
        print('/', end="")
    if turn >= 4:
        print('|', end="")
    if turn >= 5:
        print('\\')
    if turn >= 6:
        print('/', end="")
    if turn == 7:
        print(' \\')
    print(" ")

for ctr in range(1, 8):
    print_hangman(ctr)
    input()
woooee 814 Nearly a Posting Maven

You can pass an optional start location to .find() but that means iterating over the entire list several times. Another way

word="APPLE"
guess="P"
hint=["-" for ctr in range(len(word))]
print "initial =", hint
for index in range(len(word)):
    if word[index]==guess:
        hint[index]=guess

print "".join(hint)
woooee 814 Nearly a Posting Maven
  1. your indentation is not correct (and can not be corrected because you did not say what you are trying to do).
  2. you do not import math
  3. math does not contain a square_root function. Try help(math) to get a list of built-in functions for math
  4. project_to_distance does not have a return statement Click Here so

    print project_to_distance(2, 7,4)

prints None
5. the variable, scale, does not exist outside of the function in the code posted

temp1= point_x * scale
woooee 814 Nearly a Posting Maven

Start here with your post Click Here

woooee 814 Nearly a Posting Maven

I've tried a 'for i in range(53):'loop but
that doesn't work for this

Why not? It seems like the proper way to do this. Note that you salt the variables with the first 2 numbers, so the loop would run 2 less than the number of the total sequence.

Also, do not use i, O, l, etc. as variable names as they look like numbers, i.e. k+l, is that k+el or k+one?

a =  23
b = 7
c = 18

print 1, b
print 2, c
for ctr in range(a-2):
    b, c = c, b+c
    print ctr+3, c
woooee 814 Nearly a Posting Maven

Add

if ser.isOpen():    
    print "open"
    ## read and write code goes here
else:
    print "closed"

to first make sure the port is open.

Are you using Python3 and trying to write bytes instead of strings? Try

output = "1"
print type(output)
ser.write(output)

Also, this

while not connected:
    serin = ser.read()
    connected = True

only happens once so it is the same as just

serin = ser.read()
woooee 814 Nearly a Posting Maven

The docs are always a good place to start Click Here Strftime is part of the datetime.date class, not datetime.datetime.

woooee 814 Nearly a Posting Maven

PySerial finds the port by he offset so the first port would be offset 0, since it is at the beginning. Port #5 would offset the first 4 ports from the beginning so would be

ser = serial.Serial(4, 9600)

Take a look at the intro docs Click Here
and try python -m serial.tools.list_ports

I would also suggest that you sleep for one or two tenths of a second in the while loop so you don't a lot of computer resources unnecessarily.

woooee 814 Nearly a Posting Maven

I don't see anything in your code that is adding an extension.You might want to use the FileDialog module to get the file name. Also note that you have duplicate PhotoImage statements in the program.

woooee 814 Nearly a Posting Maven

For any future searchers, it is the position in the string that is important. Note that the OP is checking "n" for even or odd, not the number itself. But the code can be easily modified to do either one.

woooee 814 Nearly a Posting Maven

If you print "digit" you will see that it goes from right to left so for input that is an even number in length, the code is bass ackwards. Also a=a/10 only executes under the else. Use a for loop instead of a while loop with your logic or something like the following.

orig_number = "234756"

## sum of odd position
total_sum = 0
for ctr in range(0, len(orig_number), 2):
    print orig_number[ctr],
    total_sum += int(orig_number[ctr])
print "\n2+4+6 =", total_sum

## multiply even positions
total_multiply = 1
for ctr in range(1, len(orig_number), 2):
    total_multiply *= int(orig_number[ctr])
print "3*5*7", total_multiply
woooee 814 Nearly a Posting Maven

Unlike people, you can turn the computer off.

woooee 814 Nearly a Posting Maven

This certainly sounds like homework, i.e. lists must be used. Another way is to sort the list first and then count.

original_list = ["hello", "hi", "hi", "bye", "hi", "bye"]
original_list.sort()
counter_list = []
ctr = 0
previous = original_list[0]
for word in original_list:
    if word != previous:
        counter_list.append([previous, ctr])
        ctr = 0
        previous = word
    ctr += 1

counter_list.append([word, ctr])
print counter_list
woooee 814 Nearly a Posting Maven

There are several ways to do this. I prefer a while loop

##  Not divisible by 3
mylist = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

newlist = []
sublist=[]
ctr = 0

while ctr < len(mylist):
    sublist.append(mylist[ctr])
    ctr += 1
    if not ctr % 3:
        newlist.append(sublist)
        sublist = []

if len(sublist):
    newlist.append(sublist)

print(newlist)
woooee 814 Nearly a Posting Maven

using a list, return a 'counterlist' containing all the strings in the original list plus the number of times the string appears in the list

You want a list of lists. While the list in your post can work
CounterList = ["hello", 1, "hi", 2]
a list of list is easier to understand. In your list you would have to check the new word against every other element in CounterList (skip the number), which can be done but is more confusing.

def test_for_word(word, counter_list):
    for ctr in range(len(counter_list)):
        sub_list = counter_list[ctr]
        print "     checking sub_list (word, number)", sub_list
        if word == sub_list[0]:
            sub_list[1] += 1
            return counter_list
    counter_list.append([word, 1])
    return counter_list

original_list = ["hello", "hi", "hi"]
counter_list = []
for word_1 in original_list:
    counter_list = test_for_word(word_1, counter_list)
    print word_1, counter_list
woooee 814 Nearly a Posting Maven

Please post the entire error message as we have no idea where it may be coming from. The call to encode_files, may be the problem but that code is not included so we can't tell..

woooee 814 Nearly a Posting Maven

I would suggest that you first write it out on paper with 2 or 3 actual examples of what you want and then see how the program differs from the actual examples. For example, balance and remaining balance never change, why? How would you keep track of remaining balance when doing it by hand?

woooee 814 Nearly a Posting Maven

It is a good idea to strip() a record first, unless you are really really sure of the format.

Lambda is a bad habit IMHO. Guido wanted to omit lambda (and map, reduce, & filter) from Python3 because list comprehension is faster and the code is easier to understand. So form the habit of using list comprehension, or partial when you want to pass arguments to a function.

woooee 814 Nearly a Posting Maven

"Aligning" depends also on the font used. If you are displaying the result in the console, then the console must use a fixed witdth font. If you want to experiment, save the result to a file, open the file with any text/word processor and change the font from proportional to fixed width.

Gribouillis commented: very good! +14
woooee 814 Nearly a Posting Maven

This example from the pyplot examples page, plots two scales, and there are probably more.

woooee 814 Nearly a Posting Maven

That tells you nothing. You have to print it on the line before the error message on every pass through the for loop so you know where and what the error is.

woooee 814 Nearly a Posting Maven

If channelList has less than seven entries then you will get an error on channelList[index]. You will have to print channelList and/or len(channelList) to see where the error is.

woooee 814 Nearly a Posting Maven

We don't know which one of at least 3 or 4 possible statements is causing the error because you did not include the error message. As a shot in the dark I would suggest that you print row or cur or both somewhere around this for() statement

   cur.execute('SELECT channel FROM programs WHERE channel GROUP BY channel')

   for row in cur:

This is a link to an SQLite tutorial but should be OK for whatever SQL engine you are using
http://zetcode.com/db/sqlitepythontutorial/

woooee 814 Nearly a Posting Maven

You have to use the get() method of the StringVar. See the second, or get() example at Click Here i.e convert from a Tkinter variable to a Python variable

woooee 814 Nearly a Posting Maven

I think most programmers will tell you that the Graphics module is more trouble that it is worth. Here is similar with Tkinter and using "after" for the timing. You can easily get events, like mouse clicks, in Tkinter also Click Here

import tkinter as tk
import random

class App():
    def __init__(self):
        self.root = tk.Tk()
        self.cv = tk.Canvas(self.root, width=600, height=300) 
        self.cv.grid()

        self.start_y=30
        self.num_runs = 1
        self.flash()

        self.root.mainloop()

    def flash(self,):
        start_y = self.start_y
        start_x = 50
        color = random.choice(["blue", "yellow", "orange", "green", "white"])
        for ctr in range(random.randint(1,9)):
            self.cv.create_oval(start_x, start_y, start_x+30, start_y+30,
                                fill=color)            
            start_x += 50
        self.start_y += 50

        if self.num_runs < 5:
            self.root.after(1000, self.flash)
            self.num_runs += 1
            print self.num_runs

if __name__ == "__main__":
    app = App()
woooee 814 Nearly a Posting Maven

You can tell if a file has been changed by the size of the file and date. Check the os.stat module. st_size will give you the size. And one of the getxxtime in os.path will give you the time there is more than one

woooee 814 Nearly a Posting Maven
IndexError: list index out of range

means that at least one of the items in "x" has less than 3 elements. Before the sort, run some code to print anything with less than 3 elements and decide what you want to do with those records.

Note also that this while loop will never exit because d[2] and field do not change, (and you can not write to read only file).

    while d[2]==field: 
        fid.write(d+'\n')
woooee 814 Nearly a Posting Maven

Or put it in a Toplevel which can be positioned and sized.

woooee 814 Nearly a Posting Maven

"Refurbished" is a crap shoot. I've had good luck where they last as long as a new machine and one that died after a few months. As a general rule the warranty is 90 days so consider a new machine with less than "decent" specs as well.

woooee 814 Nearly a Posting Maven

Also, functions Click Here make it easy to test each module individually, and to see things that may be burried in a larger body of code like the duplicate similarity == 100 test here

                if similarity == 100:
                    name3 = ' '.join(name2[-1:])               
                    for item in name3:
                        if similarity == 100:
woooee 814 Nearly a Posting Maven

You should add the "\r\n" each time and test for size

def create_file_numbers(filename, size):
    output_list = list()
    count = 0
    total_output = 0
    while total_output < size:
        output = "%d\r\n" % (count)
        output_list.append(output)
        total_output += len(output)
        count += 1

    with open(filename,'wb') as f:
        f.write(''.join(output_list))
woooee 814 Nearly a Posting Maven

Use Idle to start, as it comes with Python. Later you can move to something else once you know more. Getting started with Idle (although your version of Python is hopefully newer than the one used in the link). Next start with a tutorial like this one There are more tutorials on the Python Wiki