for elem in self.programs_button:
That statement is not in the code you posted.
for elem in self.programs_button:
That statement is not in the code you posted.
Last bad joke, by me anyway. What do you call a woman with one leg shorter than the other. Eileen
The second return statement in inputPlayerLetter() never executes because the function exits when the first return is called. It should be
return Player, Computer
And you then have to catch the return when you call the function. See "the return Statement" at this link for a tutorial http://www.tutorialspoint.com/python/python_functions.htm
and https://www.safaribooksonline.com/library/view/python-cookbook-3rd/9781449357337/ch07s04.html
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.
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.
An eagle's eye can weigh more than it's brain according to birdnote.org
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
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.
When someone says "Well, to tell you the truth", I want to ask them how long they have been lying.
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
"""
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 …
Rumor has it he was quoting Mr Greenjeans
English proverb
"The soul is healed by being with children."
From the kids: Where do you find a turkey with no legs. Right where you left it.
From accuweather.com
London, England (1952)
Air pollution disaster. Smoke from burning coal mixed with fog forming sulphuric acid in the air. People wore gas masks...cars used headlights by day. After 2 weeks, the normal death rates had been exceeded by 4,000. This "killer fog" inspired England to pass its first pollution-control laws.
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"
Print the variable, url, in the funtion to see if your title is correct or not.
Solstice Sun rise and set for the Pasadena, Ca. longitude and latitude. The earliest the Sun sets is
Dec 2-6 at 16:42. The latest the Sun rises is Jan 2-13, 2015 at 6:59.
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()
Apparently Fluxbox uses xclipboard so xclip and xsel have to be installed if you want to use them. Unfortunately when doing cross-platform stuff, Linux is not one size fits all.
Produces can't find clip error on Slackware and Python 2.7 Linux uses xclip as it does not view the OS and GUI as the same thing, but "Xclip", "xclip", and "xclip -selection c" produced the same error.
Traceback (most recent call last):
File "./test_1.py", line 108, in <module>
copy2clip(byte_text)
File "./test_1.py", line 102, in copy2clip
subprocess.Popen(['clip'], stdin=subprocess.PIPE).communicate(txt)
File "/usr/lib64/python/subprocess.py", line 711, in __init__
errread, errwrite)
File "/usr/lib64/python/subprocess.py", line 1308, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
I like the Travis McGee novels in part because of the insight John D MacDonald inserts.
"This is a complex culture... The more intricate our society gets, the more semi-legal ways to steal."
"You see, dear, there is no one left to ask them a single troublesome question. Such as: Where have you been and where are you going and is it worth it."
There aren't that many, and of course this is more for entertainment. I will start it out
1. You didn't post a complete, working example to a homework problem that can be copied, pasted, and handed in.
Are you sure you even read the post as the list is still declared under the same for() loop.
You create a new list on every pass through the for() loop, so everything except for the final value in the range was garbage collected. Move the ID=[] somewhere outside of the for loop(s) so it contains all values.
for channels_id in range(4127, 4548, 70):
ID = [] # re-created every time
Also, take a look at this tutorial on lists and how to append or extend items to them. Click Here
Forks were not in use until the 18th century, so the Pilgrims at the first Thanksgiving ate eveything with only a knife and spoon.
Greased pole climbing, rock throwing and mud fighting were part of the 2004 Summer Olympics in St. Louis USA.
Weren't the 2004 Olympics in Athens?
I would use a Manager dictionary which would contain
1. a counter or other method that can be easily compared to the original to show that there is a change
2. the configuration
See the Managing Shared State heading on Doug Hellmann's site Click Here
This simple example shows that changes made to the manager dictionary inside or outside of the process can be seen by all processes
from multiprocessing import Process, Manager
def test_f(test_d):
""" frist process to run
exit this process when dictionary's 'QUIT' == True
"""
test_d['2'] = 2 ## add as a test
while not test_d["QUIT"]:
print "P1 test_f", test_d["QUIT"]
test_d["ctr"] += 1
time.sleep(1.0)
def test_f2(test_d):
""" second process to run. Runs until the for loop exits
"""
for j in range(0, 10):
## print to show that changes made anywhere
## to the dictionary are seen by this process
print " P2", j, test_d
time.sleep(0.5)
print "second process finished"
if __name__ == '__main__':
##--- create a dictionary via Manager
manager = Manager()
test_d = manager.dict()
test_d["ctr"] = 0
test_d["QUIT"] = False
##--- start first process and send dictionary
p = Process(target=test_f, args=(test_d,))
p.start()
##--- start second process
p2 = Process(target=test_f2, args=(test_d,))
p2.start()
##--- sleep 2 seconds and then change dictionary
## to exit first process
time.sleep(2.0)
print "\nterminate first process"
test_d["QUIT"] = True
print "test_d changed"
print "data from first process", test_d
##--- may not be necessary, but I always terminate to be sure
time.sleep(5.0)
p.terminate()
p2.terminate()
The United States secured the #1 ranking in wealth inequality. Note that wealth is not income Click Here
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()
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)
The tipped minimum allows employers to pay less than the regular minimum wage to workers who customarily earn tips, assuming gratuities boost them past the current $7.25 hourly rate. The cash base was 50 percent of the regular national minimum until 1996 legislation froze the lower rate at $2.13. It now amounts to 29 percent of the full minimum, which has been raised four times since.
Legislation in Congress this year would raise the $2.13 base for the first time since 1991.
How about a reference for "noli mentula" which I just looked up. Good one.
Press enter to exit
by way too many of us
I forgive not because I became a saint,
but because I’m tired of hating.
Paulo Coelho
Here is a source for those who are not too lazy too look it up themselves when they want to know more www.google.com
This thread is here for fun, it's not a research paper, so believe it or not as you choose. And only the naive believe that references make it true.
Mice multiply so rapidly, in theory a new litter every 3 weeks, that two mice could grow to 100,000 in one year. If they all lived in an area with no people, or cats and other predators of course.
Fox's "all ads all the time" in sports. It looks like I'm not alone.
From http://www.sportsmediawatch.com/2014/10/mlb-postseason-tv-ratings-2014-tbs-up-fs1-down-royals-orioles-cardinals-giants/
"Overall, six of the seven playoff games on TBS have had double-digit
increases in viewership compared to last year"
"Of the four playoff games on FS1, three rank among the network's ten
most-viewed programs since rebranding -- but the same number have
declined double-digits from last year."
Which I guess means the number of viewers since rebranding has been really low if there is a double digit decline from last year, but it is still one of their most watched shows.
Neither, as your logic is not at all correct. If you aren't going to take my advice, i.e. print "i", then there is not much point in posting anything further.
I would suggest that first you print "i" as it is probably not what you think it is. See Click Here "for loop and a string"
Second, you want to test for limits after the shift. You did not post any code to shift by "b".
To eliminate spaces, periods, etc. use (and this assumes that you don't want to shift numbers either)
if "a" <= character.lower() <= "z":
## shift by "b"
In the vein of interfacing with an alien's computer, the plot of the James Bond film, GoldenEye, was electronically transferring everything from the Bank of England and immediately triggering an EMT pulse that would corrupt/erase magnetic media.
But what does the criminal do then? Walk into a Bank of England branch and say "my computer says that I own everything. Start loading up the trucks (I mean lorries)". The bank cleark would say "Excuse me while I check one of our hundred other branches worldwide, and then we will confirm via our backup on those new fangled CDs, which use a laser so weren't affected. Oh yes, our fraud department checked for fraud immediately afer the EMT incident and has reversed those transactions."
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
Over half of fast-food "front-line" workers are on some kind of government assistance (foodstamps, etc.) because they don't make enough. The average pay for the president of a fast-food company is $124 million.
From http://www.reuters.com/article/2013/10/15/us-usa-fastfood-wages-idUSBRE99E0N920131015
"It doesn't matter whether you work or shop at McDonald's or not, the low-wage business model is expensive for everybody," said NELP policy analyst Jack Temple, who worked on the report. "Companies ... are basically pushing off part of their costs on the taxpayers."
This ends up costing U.S. taxpayers billions of dollars a year, the study said.
Data from the U.S. Census Bureau and public benefit programs show 52 percent of fast-food cooks, cashiers and other "front-line" staff had relied on at least one form of public assistance, such as Medicaid, food stamps and the Earned Income Tax Credit program, between 2007 and 2011, researchers at the University of California-Berkeley and the University of Illinois said.
And by association, disk drive manufacturing and jobs.
What, no one has mentioned writing a sloppy, undocumented program because it is a one-time quick and dirty use. Murphy's law says you will still be using that program 10 years from now and it will be much, much longer.
And if you want better answers you will have to ask better questions. You have said nothing about updating the label multiple times or anything about the conditions under which you want to update it, so we can't do any more than has already been done based upon the question asked.
You only call update_label_1 one time so the label is only updated once. This updates the label every time the button is pushed.
class UpdateLabel():
def __init__(self):
self.master = tk.Tk()
self.update_ctr = 0
self.label1_text = tk.StringVar()
self.label1_text.set("initial value")
self.label1=tk.Label(self.master, textvariable=self.label1_text,
fg='blue', font=("Arial", 36, "bold"),
background='#CDC5D9')
self.label1.grid(row=0,column=0)
self.master.grid_columnconfigure(1, minsize=100)
self.label2=tk.Label(self.master,text='Initial value',
fg='blue', font=("Arial", 36, "bold"),
background='#CDC5D9')
self.label2.grid(row=0,column=2)
tk.Button(self.master, text="Quit", command=self.master.quit,
bg="red").grid(row=10, column=0, columnspan=3)
tk.Button(self.master, text="Update Label",
command=self.update_label_1).grid(row=5, column=0)
self.master.mainloop()
def update_label_1(self):
## update label1 by changing the StringVar()
self.update_ctr += 1
self.label1_text.set("update #%d" % (self.update_ctr))
self.label1.config(bg="yellow")
UpdateLabel()
grid() returns None so self.label1 equals None in the code you posted.
There are two ways to update a label, illustrated below. There is way too much code here for me to traverse so the following is independent of any code you posted.
class UpdateLabel():
def __init__(self):
self.master = tk.Tk()
self.label1_text = tk.StringVar()
self.label1_text.set("initial value")
self.label1=tk.Label(self.master, textvariable=self.label1_text,
fg='blue', font=("Arial", 36, "bold"),
background='#CDC5D9')
self.label1.grid(row=0,column=0)
self.master.grid_columnconfigure(1, minsize=100)
self.label2=tk.Label(self.master,text='Initial value',
fg='blue', font=("Arial", 36, "bold"),
background='#CDC5D9')
self.label2.grid(row=0,column=2)
tk.Button(self.master, text="Quit", command=self.master.quit,
bg="red").grid(row=1, column=0)
## update the label in two different ways
self.master.after(2000, self.update_label_1) ## sleep for 2 seconds
self.master.mainloop()
def update_label_1(self):
## update label1 by changing the StringVar()
self.label1_text.set("2nd value")
self.label1.config(bg="yellow")
## update label2 by setting the text
self.label2["text"] = "third value"
self.label2["fg"] = "green"
## this is the same as the above line
##self.label2.config(text="third value")
UpdateLabel()
You would use a list of lists. One sub-list for each row, so if the data is 1, 3, 2, 7, 5 and you are drawing the third row, you would place an "X" in the element at offsets 1,3, and 4 since those 3 all require a third row. Once that is done you can just join and/or print each sublist.