Tagged Questions
-1
votes
1answer
27 views
Using checkboxes in python to select which files to write/export
I have a UI with 8 checkboxes. The idea is that depending on which ones are checked, it will choose what commands to send to telnet and what data files to return.
Currently I just have 8 IF ...
0
votes
3answers
75 views
Python if/elseif construction as dictionary
In Python I use regularly the following construct:
x = {'a': 1, 'b': 2, 'c': 3, 'd': 4}
y = x[v] if v in x.keys() else None
where v is normally one of the dictionary values, and y gets the value of ...
1
vote
2answers
34 views
Global Variables in functions with if statements
Okay, I am currently doing a project to make a blackjack game in python and I'm having some trouble. One of my issues is I dont know when to define a variable as global, specifically in functions ...
0
votes
1answer
27 views
IndentationError: unindent does not match any outer indentation level - backslash
I am following a tutorial on how to make a simple pong game in python and I get and error reading, IndentationError: unindent does not match any outer indentation level. It particularly points to the ...
2
votes
4answers
62 views
Code is looped again and again
I have next code:
def begin_game():
print "You landed on planet and see three rooms."
door=int(raw_input("Pick number of door>>>"))
print "You approach and see that you need to ...
0
votes
4answers
66 views
Python newbie: why it works with return and not with print? (inside an if statement) [duplicate]
Why using print won´t work, and it does work using return?
I want to output the bigger number:
def bigger(x,y):
if x<y:
return y
return x
print bigger(2,7)
It prints out:
7
...
0
votes
1answer
42 views
Open file if 2 conditions are true, else print
I am trying to get a piece of python (2.7) code to work. The code is as followed:
import os
def parseOptions():
import optparse
parser = optparse.OptionParser(usage= '-h')
...
0
votes
1answer
65 views
Python if statement not working
I have an if/else statement in python, and I want to do nothing when it goes to the else statement.
I am reading a list of words, finding the palindromes (eg 'abba') and printing them out. It ...
0
votes
0answers
21 views
“PYTHONPATH”, going through the list and check elements
i have to set my variable
maya_env_variable = "PYTHONPATH"
after i have to set a new path
new_path_list ['User/Desktop']
i have to get the current value of my PYTHONPATH using ...
-1
votes
4answers
76 views
Issue with “if” statement in Python
I have one file and I am trying to populate second file using its data in Python. While populating I am applying some if statements to manipulate one column in the 2nd file.
What I want to perform ...
0
votes
3answers
71 views
Python if statement problems
I am trying to make something work with if statements, but instead of choosing the correct one, it chooses all of them. So, the code below:
money=100
if money==100:
print('You buy a pair of ...
0
votes
3answers
54 views
Python print out float or integer
How can i print out float if the result have decimal or print out integer if the result have no decimal?
c = input("Enter the total cost of purchase: ")
bank = raw_input("Enter the bank of your ...
1
vote
1answer
77 views
Python: if in, then match on field of row found in
The title may be a little confusing, but I was wondering if there was a way to us "if in" to look at other fields in an array once it is matched. I figure if there isn't something built-in, i'll just ...
85
votes
14answers
6k views
Python syntax for “if a or b or c but not all of them”
I have a python script that can receive either zero or three command line arguments. (Either it runs on default behavior or needs all three values specified.) What's the ideal syntax for something ...
2
votes
4answers
94 views
python. if var == False
In python you can write an if statement as follows
var = True
if var:
print 'I\'m here'
is there any way to do the opposite without the ==, eg
var = False
if !var:
print 'learnt stuff'