Questions tagged [if-elif]
10 questions
1
vote
2 answers
Can someone explain to me the commands [0][1][2] in the code below and how they work
if __name__ == '__main__':
N = int(input())
my_list = [] # Initialize an empty list to perform operations on.
for _ in range(N):
command = input().split() # Read the command as a space-separated string.
if…

Kigoni mike
- 11
- 1
0
votes
2 answers
Why are these errors appearing with if and else functions
Just started Python programming and I am currently learning about the if, else and elif functions from an online course i bought. I did everything word for word but i keep getting errors on VSC. The course is using different software, so maybe it…
0
votes
2 answers
bash if-elif-else sequence get "conditional binary operator expected on first elif
learning / relearning bash scripting. The following if - elif statement gets a conditional binary operator error on the first elif:
if [ $len -eq 1 ]; then
grep -i -H $1 *.org
elif [[ [ $len -eq 2 ] -a { [ $1 == "keyword" ] -o [ $1 == "todo" ] }…

swgeek
- 11
- 4
0
votes
1 answer
Why won't my warm/cold elif statements print until the end of program?
Im trying to make it so the warmer/colder text appears after input, but it doesn't print until the end of the program?
I think it has something to do with the elif statement? i keep having trouble with those in other projects (had to put hangman on…

deafening_radio
- 11
- 1
0
votes
0 answers
Loop Over Multiple Columns with String Data & Create New Variable
I'm working in Rmarkdown.
I have 11 columns in a dataframe that all have correct and incorrect answers as strings. I would like to loop over the 11 columns and score correct answers as 1 and incorrect ones as 0. Then, I would like to have a new…

JimStir
- 1
0
votes
1 answer
Why am I getting different values if I change my 'elif' statement to 'if'?
I have a code where I am trying to compare hydrophilic and hydrophobic interactions. My categories are 'Hydrophilic', 'Hydrophobic' and 'Other'. Every time I try to find out how many of each interaction category there is, I always get always get…

amy-elouise
- 35
- 6
0
votes
1 answer
I this a good way to write this
I had a small project, I am a beginner with python in the 100 days of code with Dr.Angela Yu and was tasked to write code for a leap year checker. I wrote the code different from her and wanted to know was this ok to do since it ended up working…

NolongerHuman
- 13
- 2
-1
votes
0 answers
Why am I getting a key error in my text based game?
I am creating a text based adventure game for one of my college courses. I need to be able to move through the rooms, pick up all the items, and get to the 'Boss' room to finish the game. It is not finished, but so far I was able to make movement…

harperwill7
- 1
- 2
-2
votes
1 answer
Why dose it insist that I have a semi-colin on elif my statement?
I am a beginner having some trouble with my e.g. code and cant figure out what is wrong with it
any help would be much appreciated!
answer = input("Do you want to play (yes/no)?\n>")
if answer .lower() .strip() == "yes":
answer =…

soda bob
- 9
- 1
-6
votes
3 answers
IF and ELSE in excel
enter image description here
Value1 Value2 Color
2 16 =IF(A2>5,"Red", IF(AND(5>A2>1,40>B2>1,"Yellow")),IF(AND(5>A2>1,40>B2>60,"Red")),IF(AND(5>A2>1,60>B2>100,"Yellow")),"Green)
The logic for which, I believe is:
If "Value1" > 5…

Martine
- 1
- 1