Society has advanced to the point where you are officially dumber than a 12 year old.
"12 Year Old Alex Miller Spots Major Firefox Security Bug and Gets the $3000 Bounty!"
http://www.techdrivein.com/2010/10/12-year-old-alex-miller-spots-major.html
Society has advanced to the point where you are officially dumber than a 12 year old.
"12 Year Old Alex Miller Spots Major Firefox Security Bug and Gets the $3000 Bounty!"
http://www.techdrivein.com/2010/10/12-year-old-alex-miller-spots-major.html
1) Choose a title that will get people to read the question
2) Sort the list and replace the first 5 numbers with the last 5
Assuming k is an integer, it will never be less than "n" because "n" is a string, as already stated. Print both "k" and "n" to test.
def otsi(k):
if (k < n):
print "k < ", k, n
#
# instead of recursion you should be using a while loop
# recursion is rarely, if ever, used in actual code
def otsi(k):
## while (k < n):
## or even better
for k in range(n):
print k, n
lmargid.append("+")
lmargid.append("-")
print lmargid
#
# or even, even better
lmargid.append("+-"*n)
You enter all of the values each time so they would be whatever was entered for each while() loop. Note that if something other than "y" is entered for trimming and wastage, the total will not be calculated. It is simpler to read the code if it is in the following form:
if add != 'y' and add != 'Y':
#
# use instead
if add.lower() != 'y':
#
# or
if add in ['y', "Y"]:
#
#
trim_waste = 0.05
add = raw_input('Add 5% for Trimming and Wastage? (Y/N): ')
print "\n-------------------------\n"
if add.lower() != 'y':
trim_waste = 0.0
last = total + (total * trim_waste)
Double check your average calculations, as generally you can not add averages together. See "Conditionals" here.
if average > 90:
grade = "A"
Etc
So you want to modify
for row in cursor
print row
##
## to
for row in records:
print row
I like using deque's appendleft for coding reverse sequence. You would of course use loops for row and column and eliminate the redundant statements here:
from collections import deque
ctr = 12
print_list = deque()
print_list.append(ctr)
ctr -= 1
print_list.append(ctr)
ctr -= 1
print_list.append(ctr)
ctr -= 1
print print_list
print_list = deque()
print_list.appendleft(ctr)
ctr -= 1
print_list.appendleft(ctr)
ctr -= 1
print_list.appendleft(ctr)
ctr -= 1
print print_list
I don't use MySQL, but try using this line instead and see what happens.
abc = "SELECT * FROM Details"
records = cursor.fetchall()
and is the table named "Details" or "mydb".
I forgot to mention that even though I don't know what a chaos knight is, I like it.
But i want the file to call out the numbers, instead of a list
If you can't print a simple list, then you want to start at the very beginning, since counting is more complicated than printing (which is a simple loop). Some links to on-line books
http://www.greenteapress.com/thinkpy...tml/index.html
http://diveintopython.org/toc/index.html
(see "Beginner's Guide" and "Python Books") http://wiki.python.org/moin/
Duplicate post deleted. This seems to be duplicate post day.
The easiest way is to use Python's count() function (and then test for a result > 0) for smaller groups of numbers. Some info on using lists. A list can also be used by element or index number. Element[0] = the number of zeros found, element[1] = number of ones, etc. which can then be multiplied by the element/index number to get the result. You can also use a dictionary, with the key equal to the number, pointing to an integer that counts the number of times the number appears.
number_list = [5, 3, 11, 3, 7, 3, 5, 5, 11, 7, 7 ]
for num in range(12):
print "%d:%d:%d" % (num, number_list.count(num), num*number_list.count(num))
A place to start, without coding the solution for you. Post your code for help with further problems.
main_list = [['a', 'b', 'c', 'd'], ['e', 'f'], ['g', 'h']]
for each_list in main_list:
print "\n New List"
for ctr in range(len(each_list)):
print ctr, each_list[ctr]
Check out ShedSkin to speed up Python code. I don't think you can learn C/C++ in the next few months, but it depends on how complicated the programs are. Some Python links
http://www.greenteapress.com/thinkpython/html/index.html
http://diveintopython.org/toc/index.html
(see "Beginner's Guide" and "Python Books") http://wiki.python.org/moin/
Duplicate post deleted.
What happens if you have more than one key with the same maximum? Instead of print, store the key and item if it is greater than the maximum so far.
You don't return or receive anything for numbers not equal to zero. The function calls itself many times. Each function call must receive the return value when the function it calls finishes, and then return that value to the function it was called by.
def recursion_test(value):
""" recursion example incrementing a counter for each function, and
printing each function value for that function call
"""
print "value now =", value
if value > 10: ## exit recursion loop
return value
new_value = recursion_test(value+1)
return new_value
print recursion_test(0)
Also, you can check wxpython and qt to see if they will run on Solaris. It doesn't matter which GUI toolkit you use as you can find password entry programs for any of them on the web.
dict={'COUNTY': COUNTY, 'TOWN': TOWN}
You should print the dictionary as it will only contain one entry. Also, do not use "dict" as a name as that is a reserved word used to convert to a dictionary. Ditto for 'locale' (instead use town_dict, etc. as it then lets the reader know what the dictionary contains).
I am still getting a systex error when closing the file
We can't really guess what that is. Post the entire error message. As a general rule, check that line of code and the previous for the same number of open and closing parens. If there is a paren error on the previous line, the interpreter sees the next line as a continuation line. Also, you close the file, but never open it, so that could be one of the errors.
Put the above code in a function and then call the function from a loop. You can use one function to get the width or the length as well by passing the maximum allowed value and the literal to print, "Width" or "Length", to the function. Note that the Python Style Guide specifies variable names and function names should be all lower case.
ask = "y"
while ask.upper() == "Y":
calculate_costs() ## calls above code as a function
ask = raw_input("Would you like to calculate another ('Y' or 'N')? ")
Lists have min and max functions which could also be used. For both code solutions, what happens if there is more than one month with the same rainfall?
def lowest_month (rainfall):
lowest = min(rainfall)
return MONTH[rainfall.index(lowest)], lowest
Id like it to look like this Multiply ,x times ,y
See string formatting.
print "Multiply", x, "times", y
print "Multiply %d times %d" % (x, y)
And this will always be zero.
i=[(curletter+key)-(curletter+key)]
You can just add or subtract the shift value, depending on whether it is encrypt or decrypt, and test for < 0 or > length and add or subtract length. You can in fact use the same function for encryption and decryption by sending a switch to the function telling it which you want to do.
def do_some_testing(letter_in):
## decrypt = shift each letter backward by 3 letters
letters=list("abcdefghijklmnopqrstuvwxyz")
shift = 3
if letter_in in letters:
current_location = letters.index(letter_in)
new_location = current_location - shift
if new_location < 0:
new_location += len(letters)
return(letters[new_location])
return("*") ## error
##------------------------------------------------
print "z -->",
print do_some_testing("z")
print "a -->",
print do_some_testing("a")
print "-"*30
orig_string = "d txlfn eurzq ira"
decrypt_list = []
for letter in orig_string:
decrypt_list.append(do_some_testing(letter))
print orig_string
print "".join(decrypt_list), "\n"
I want it to simply give me the logged-in users password.
Generally speaking, programs do not know passwords. A programs takes the password the user entered, converts it using some encryption algorithm, and compares to the stored password (stored in encrypted form only). Otherwise, anyone could steal any password with a simple program.
This will never be true
if (curletter+key)>(25):
if (curletter+key)<0:
You can test for membership in the rows list (already input), assuming you want to do this on the input value.
if input_num not in rows:
rows.append(input_num)
#
# or remove each number as it is entered
input_list = [str(x) for x in range(1, 10)]
while len(input_list):
print "Enter a number from", input_list
num = raw_input("Enter: ")
if num in input_list:
input_list.remove(num)
## etc
You can use split() if I understand correctly.
locTextFormat = "COUNTY --- TOWN"
print locTextFormat.split("---")
##
## or is it
COUNTY = "test_county"
TOWN = "test_town"
print COUNTY + " --- " + TOWN
print "%s --- %s" % (COUNTY, TOWN)
Vegaseat did one a while ago and posted it http://www.daniweb.com/forums/thread198855.html I think most GUI toolkits include methods to do this.
import Tkinter as tk
root = tk.Tk()
def show_pw():
pw = pw_entry.get()
label2['text'] = pw
label1 = tk.Label(root, text="Enter password for user Frank: ")
# shows only * when entering a password
pw_entry = tk.Entry(root, show="*")
# cursor here
pw_entry.focus()
# click on button to show the password
button = tk.Button(root, text='show password', command=show_pw)
# label to show result
label2 = tk.Label(root)
# widget layout, stack vertical
label1.pack()
pw_entry.pack()
button.pack()
label2.pack()
# start the event loop
root.mainloop()
And on Linux, we can use termios, but don't know if is it also available on Solaris.
import termios, sys, os
#import termios, TERMIOS, sys, os
TERMIOS = termios
def getkey():
fd = sys.stdin.fileno()
old = termios.tcgetattr(fd)
new = termios.tcgetattr(fd)
new[3] = new[3] & ~TERMIOS.ICANON & ~TERMIOS.ECHO
new[6][TERMIOS.VMIN] = 1
new[6][TERMIOS.VTIME] = 0
termios.tcsetattr(fd, TERMIOS.TCSANOW, new)
c = None
try:
c = os.read(fd, 1)
finally:
termios.tcsetattr(fd, TERMIOS.TCSAFLUSH, old)
return c
if __name__ == '__main__':
print "type something...'q' to quit"
s = ''
while 1:
c = getkey()
if c == 'q':
break
print "captured key", c, ord(c)
s = s + c
print "Password =", s
I've added some notes on what is and is not happening. When you don't understand something it is usually good to break it into smaller pieces and solve each piece individually. This code is not even good enough to correct so start again and post back, next time include an input and desired output example as well, to make sure everyone is using the same definition for 'transposition'.
def transpose(matrix):
l=len(matrix)
i=0
j=0
Aj=[]
T=[]
for i in range(l): ## is this range one or range el?
Ai=matrix[i] ## Ai will always contain the last matrix value
print "Ai =", Ai ## print to show each value is overwritten by the next
li=len(Ai)
i+=1 ## this "i" variable does nothing and can be deleted
for j in range(li):
Aij=Ai[j] ## will always contain last value in the range
j+=1 ## does nothing and can be deleted
for i in range(l):
Aj.append(Aij) ## continuously appends the same value = Aij
i+=1 ## does nothing so can be deleted
for j in range(li):
T.append(Aj) ## continuously appends the same value = Aj
return T
Would be great if you could sent a TV signal through this first with a routine to define and remove popups. We will probably be there some day soon.
o, I have new_list = [52, 56, 57, 72, 85, 94]. I need to get difference between numbers from the list and average [52-51=1, ..., 72-51=21 and so on..], then raise the square of each, sum all them and divide from list length
Process each number and use a list if you want to store more than one number.
for num in new_list:
total += num
square_num =
square_total += square_num
average_dif = average_num - num:
etc
You can also use an indicator for wrong answers:
right_answers = True
while (abs(s1 - s2)!= 2):
x = input("Faktor: ")
y = input("Faktor: ")
z = input("Rezultat: ")
if z == x * y:
s2 = s2 + 1
print "Trenutni rezultat : ", s1, " : ", s2
else: ## assuming the above was the correct answer
right_answers = False
#
# finally
if right_answers:
print "correct or whatever"
else:
print "wrong"
# ----------------------------------------------------------------
# with a function that can be called as many times as you want
def multiply_get():
a = input("Faktor: ")
b = input("Faktor: ")
c = input("Rezultat: ")
if c == a * b:
return True
return False
And whatever the case, you want to verify that the correct data was entered.
if choice not in ["4", "6", "10", "12", "20", "100]:
print "Incorrect number entered"
Also, place this under a while() loop, so it will loop back if an incorrect number was entered.
MsgDataType = c_uint8 * 8
msg = MsgDataType()
Not that you are using the same name twice.
print type(msg)
it may be a class in which case you would access it with
msg.field_name
simple program, help
I have never understood this type of title. If you don't know how to do it, then how do you know it is simple. And if it is simple, then why do you need help?
Print the "nums" list inside the for() loop. It possibly contains more than you think it does. To add the numbers up you have to go through each list one by one, and add each number individually to a total. Python does have a built-in function to do this, but I am assuming that this is some type of homework and you are supposed to do it yourself.
Also, the first 2 lines of code do nothing. You can delete them.
this will check to see if they typed in "d4"
This assumes that the user entered "d4" We do not know this. It is possibly more likely that just a "4" was entered as the "d" is not necessary. If a "4" was entered then the code would be
rand_d = random.randrange(int(choice))+1
So on the one hand we have a leading "d" probably not entered, and on the other we have 6 random statements, where one would do if a number was entered. We'll have to wait for the OP to reply and see.
I would suggest a print statement or two so you can tell what the program is doing. For future postings, we have no idea what "choice" is supposed to contain.
import random
choice = raw_input("what die would you like to use: ")
d4 = random.randrange(4)+1
d6 = random.randrange(6)+1
d10 = random.randrange(10)+1
d12 = random.randrange(12)+1
d20 = random.randrange(20)+1
d100 = random.randrange(100)+1
print "comparing choice =", choice, "and d4 =", d4
if choice == d4:
print "d4"
print "comparing choice =", choice, "and d6 =", d6
if choice == d6:
print "d6"
Frist, you should test the findSlope function (see the python style guide. Function names are all lower case with underscores and you should not use "i", "l", or "O" as single digit variable names because they can look like numbers).
def findSlope (x1, y1, x2, y2):
rise = y2 - y1
run = x2 - x1
if run == 0:
slope = "undefined"
else:
slope = rise/run
print "slope is", slope, rise, run
return slope
findSlope(1,16,10,31)
yields a slope of 1 because you are only using integers.
def findSlope (x1, y1, x2, y2):
rise = y2 - y1
run = x2 - x1
if run == 0:
slope = "undefined"
else:
slope = rise/float(run)
print "slope is", slope, rise, run
return slope
findSlope(1,16,10,31)
yields a slope of 1.6666... --> converting to a float.
For reading the file, try:
for rec in inFile:
print"----- new record -----"
rec = rec.strip()
rec_list = rec.split(',')
ctr = 0
for el in rec_list:
print ctr, el, type(el) ## is a string, not an integer or float
ctr += 1
Also, you read 2 different files, but only explain what one of them is???
for key_constant, pressed in enumerate(pressed_keys):
If you are asking about this line (you didn't say), enumerate returns a counter and the original variable, with the counter incremented by one for each item in the list. It is similiar to this, as printing the variables will show
ctr = 0
for pressed in pressed_keys:
print ctr, pressed
ctr += 1
##
##
## you can also try
for test_it in enumerate(pressed_keys): ## don't split into two variables
print test_it, type(test_it)
First, you have to detect the object itself. Then you can construct a 3-4-5 triangle, or continue the same length as the base, creating a "T" with one of the sides, and see if lines drawn to the top of the "T" are the same length. There is much info on the web about edge detection and determining shapes. We are coders, not theorists. First you have to decide on a system, then produce the code, then you can ask questions here about your code.
This thread is duplicate from this one http://www.daniweb.com/forums/thread317912.html see my answer there.
And was copied to bytes.com. At some point you will have to write some of the code yourself.
Take a look at pexpect in addition to subprocess.
key = key1 * (len(message)//(len(key1) + 1))
key1 is never defined anywhere. I think you meant something like:
key = key * (len(message)//(len(key) + 1))
although it's impossible to tell what you want from "it doesn't work". Note that the code as posted will yield a zero since "key" is longer than "message". Also, check the arithmetic
len(message)//(len(key1) + 1))
key1 -->
len(message
//
len(key)+1
In the future, include the error message as you won't get any responses to "it doesn't work".
You can replace line 3 with line = lines.rstrip().split(',')
Note that this will probably cause an error at
l2.append(line[1])
because length will be too short. You should be testing for length anyway:
f = open('datagen.txt')
for lines in f:
line = lines.strip().split(',')
if len(line) > 1:
l1.append(line[0])
l2.append(line[1])
Line 27, string is never defined, and you should not use "string" as a variable. That name is already used by Python.
message_text = "Message Box"
message.setText(message_text)
At line 46, etc. use a variable to store the changes.
message = "attackatdawn"
cap_str = message.upper()
print message, message.upper()
Line 49: Trying to make the keyword repeat to make it at least as long as the message to encode (but this was a failure as well)
No idea what "this was a failure as well" means.
Line 57: Why does this not undraw the rectangle?
No idea what the graphics module uses (no one really uses graphics), but generally you have to use a variable to point to the object's location in memory, and then tell the program which object/memory location to undraw.
withdraw_rec = Rectangle(Point(80,155), Point(158, 110)).draw(win)
dont_withdraw_rec = Rectangle(Point(180,55), Point(258, 10)).draw(win)
withdraw_rec.undraw()
I would suggest using a single list with a sub-list containing [item, quantity, price]. Online explanations for lists and enumerate. Your original code slightly modified is below. Note that process_order_quantity will have to be changed to receive a single quantity and item, (which assumes that the discount is for single items > 10). You might want to return the discount and add it to the sublist as well. So as to not form bad habits, read the Python Style Guide when you have time (function names are all lower case with underscores, "_")
#get user input
items_list = []
subtotal = 0.0
for i in range(0,2,1):
item = str(raw_input('Enter an item: '))
quantity = int(raw_input('How many of these do you want? '))
price = float(raw_input('Enter the price: '))
items_list.append([item, quantity, price]) ## <----- appends a list
## add the subtotal
this_subtotal = process_order_item(quantity,price)
subtotal += this_subtotal
print "subtotal is now", subtotal, "\n"
#loop over the lists -------------------------------------------------
#
# print each sublist
for sublist in items_list:
print sublist
# print item, quantity, price
for this_sublist in items_list:
print "item =", this_sublist[0], ", quantity =", this_sublist[1], \
", price =", this_sublist[2]