Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I'm working with big multidimensional arrays. I want to know after x loops the values S,S2,E,E2
I want to find all the solutions of a loop.
I have a code that iterates with a greedy. My output is a list of numers. I want to save the arrays that generate those numbers. My code:
while True:
if f2<f:
f,S,S2=f2,E,E2 # f is a value and S and E are arrays
......
print f2-f
else:
break
If i run this code I have a list of f2-f but I need also to save the f,S,S2,f2,E,E2 created in each passage of the while.. Thank you
results = []
while True:
if f2<f:
f,S,S2=f2,E,E2 # f is a value and S and E are arrays
......
results.append((f,S,S2,E,E2))
print f2-f
print "intermediate result:", results[-1]
else:
break
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
Basically, im trying to make array of arrays in python and i don't know how really. It needs to be in "for" loop and each time it goes trough loop, it needs to add array of some numbers to the array of arrays but of course on index+1
EDIT:
this is what i already tried, but it gives me error:
for x in range(5):
poljeRazina[x][x]=1
In Python, arrays are called Lists. This could be helpful when googling.
Also, you can declare them like this (depth-based):
x = [[]]
Then...
for big in range(10): #outer loop
for small in range(10): #inner loop
x[big].append(small*big) #add new number
print('%03d' % x[big][small], end=" ") #we print the number padded to 3 digits
x.append([]) #add another internal list
print() #move down to next line
Equals...
List comprehension might help
[list(range(i)) for i in range(5)]
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
Can someone please explain how this works? Like, how does it count?
for a in range(2,5):
for b in range(1,2):
print (a+b,end=" ")
print("---",end=" ")
the output is: 3 --- 4 --- 5 ---
It just adds 2, 3, 4 with 1 and prints the result.
In Python-3.x, print() is a function and the argument end in it means
string appended after the last value, default a newline
Values returned by range(x, y) are [x, y-1]
If you don't know the usage of a function, you could open ipython and type something like the following:
help(print)
help(range)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How to check if part of text is in tuple?
For example:
my_data = ((1234L,), (23456L,), (3333L,))
And we need to find if 123 or 1234 is in tuple.
I didn't worked lot with tuples before.
In array we use:
if variable in array
But its not working for tuples like my_data
PS. 1st answer solved problem.
def findIt(data, num):
num = str(num)
return any(num in str(i) for item in data for i in item)
data = ((1234L,), (23456L,), (3333L,))
print findIt(data, 123)
Output
True
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
So I'm making a quiz and when I make an if statement in python to put a question I have to put the print before it(which I'm using at answers). So my question is how to make it come after without stopping the if statement. Any ideas appreciated. Sorry if its hard to know what I'm trying to say I'm a little new to python.
Something like this maybe?
answer = input ('Who was the last king of Rome? ') #use raw_input for python2.x
if answer == 'Tarquinius': print ('correct')
else: print ('incorrect')
print 'asdf' if 1 == 2 else 'fdsa'
Or if you don't get that this does, try this:
print "ok..nice" if raw_input("how are you ") == "ok" else "well, that's too bad"
Apparently people don't know the new inline if syntax, and think i'm trolling.
This should all be written in 1 line and does not require splitting.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
This is my code:-
print "Welcome to the English to Pig Latin translator!"
original = raw_input("Write a word")
if len(original)>0:
print origninal
else:
print "empty"
so here original is my variable. i get the string "empty" if user inputs no words, but if user inputs any words which is more than 0 characters (as defined in if statement) i am getting an error saying "name original is not defined".
I want the console to print the users input. What is wrong in my code?
There is a typo in your code. origninal should be original
if len(original) > 0:
print original
else:
print "empty"