Linked Questions
13 questions linked to/from What is the correct syntax for 'else if'?
0
votes
2
answers
14k
views
Python Return Invalid Syntax Error [duplicate]
I am writing a simple python program on a raspberry pi and I am quite new to python programming. I have defined a function called GetMessage which has no parameters and returns a variable which I ...
-4
votes
3
answers
138
views
Simple Syntax Error [duplicate]
Python says it has a syntax error in this line " elif (i%7==0) or str.count(str(i),'7')>0: " and I cannot figure it out.
I'm new to Python so it must be something simple.
k=int(input("enter the value ...
1
vote
1
answer
85
views
Python else not working correctly [duplicate]
I'm writing python scripts to count how many times certain strings occur but it seems like the else is not working correctly.
Here is my codes:
import os
user_input = "#"
directory = os.listdir(...
1
vote
4
answers
6k
views
checking next element in for loop
Let's say I have this array:
arr = ["foo","bar","hey"]
I can print the "foo" string with this code :
for word in arr:
if word == "foo":
print word
But I want also check the next word if ...
2
votes
3
answers
9k
views
copy section of text in file python
I need to extract values from the text file below:
fdsjhgjhg
fdshkjhk
Start
Good Morning
Hello World
End
dashjkhjk
dsfjkhk
The values I need to extract are from Start to End.
with open('path/to/...
0
votes
3
answers
4k
views
Beginner Python: If-else statements, formatting errors
I am a beginner programmer in python and I need assistance with some code. Attached is the code I have been working on. The purpose is to take a dollar amount like 305.67 and convert the number to a ...
-4
votes
1
answer
18k
views
SyntaxError: expected ':'
what should I do?
I gave this error:
mylist=input('please inter your condition :')
If mylist == '10' or '9' or '8':
print('well')
print('well done')
else if mylist == '7' or'6' or '5' or '4' or '...
0
votes
3
answers
710
views
Get value from an "if " statement with multiple conditions
I have an Excel file and I want to extract some values from it whe it finds 7 or 14 or 13 in the following columns: remainingDaysE or remainingDaysG or remainingDaysI
I am having the following code in ...
-3
votes
3
answers
149
views
Inconsistency with else statements?
This is a revised version of my previous question.
When using else-if as a shortcut, I'm not exactly sure why, syntax wise, it performs the same functionality as nesting if-else statements. Let's say ...
0
votes
2
answers
87
views
'ELSE' Running even if 'If' is true
I was Trying to Make a Simple Maths Calculator.
pi = math.pi
e = math.e
φ = 1.618033988749895
while True:
sh= input("MATHS CALCULATOR: ")
if sh== "Values":
va=...
-2
votes
1
answer
143
views
In discord.py when I use more than 1 `on_message` it does not works, only the last one works
This is my code, and on_message is not working when used twice, only the 2nd one is working. Please help me.
async def on_message(message):<br>
if message.content.startswith('-coinflip'):<...
0
votes
1
answer
40
views
How do I prevent all 3 variables from showing same number in print output?
My code below passes all tests with the exception of when 2 or 3 of the numbers are equal. In that case, my output is showing 2 or 3 of the same number, i.e. 7 three 3 times if x y and z are all ...
1
vote
1
answer
41
views
the right way to use if, else, elif on python?
I just started learning python +-36 hours. I'm new to this whole coding/programming thing. I'm trying to build a simple program for my exercise, basically my program will asks "Are you willing to ...