If/Elif Python Statement [closed] - python

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
New to this. My autochecker says that line 3 is incorrect.
score = input("Enter Score: ")
s = float(score)
if s >= 0.9
("A")
elif s >= 0.8
print ("B")
elif s >=0.7
print ("C")
elif s >=0.6
print ("D")
elif s < 0.5
print ("F")
else
print ("Enter number")

You need a colon after each if/elif/else line.
You need to add print before "A".

Related

My "test if this is a prime number" code crashes when I test numbers greater than 4 [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed last month.
Improve this question
I'm a Python noobie, please have mercy.
I tried to create a code to test if a given number is a prime number. I tried the %, sqrt, and n methods. All ended with the same result: when I try to test the code for numbers greater than 4, the code returns NULL and says "Process finished with exit code 0"
Can you please help me figure out what I'm doing wrong?
Here's the code I wrote (this is the 'n' method where I apply % to numbers all the way up to n; I know it's not the most efficient, but I'll fix that after I make sure it works):
x = 5
if x > 1:
for i in range(2, x):
if (x % i) == 0:
print("NOT prime")
break
else:
print("YES, it's prime")
else:
print("NOT prime, because the number is < 1")
break should be indented once more, so it does not break the loop when it is not a prime.

elif statement SyntaxError: invalid syntax [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
Could somebody kindly let me know why is there a SyntaxError? I use macOS Mojave and have installed IDLE version 3.7.1.
if name == 'Alice':
print('Hi, Alice.')
elif age < 12:
print('You are not Alice, kiddo.')
elif age > 2000:
print('Unlike you, Alice is not undead, immortal vampire.')
elif age > 100:
print('You are not Alice, grannie.')
Indentation is wrong:
name = input('whats your name? ')
age = int(input('whats your age? '))
if name == 'Alice':
print('Hi, Alice.')
elif age < 12:
print('You are not Alice, kiddo.')
elif age > 2000:
print('Unlike you, Alice is not undead, immortal vampire.')
elif age > 100:
print('You are not Alice, grannie.')
'elif' should have the same indent as the 'if'
remove white space before your elif
if test expression:
Body of if
elif test expression:
Body of elif
else:
Body of else

How to fix a while syntax error in python? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I'm getting a syntax error on my 2nd while loop. Can't figure out why, any help appreciated :)
#intro
print("Welcome to my prime number detector.")
print("Provide an integer and I will determine if it is prime.")
#again loop
again = "Y"
while again == "Y":
num = (int(input("Enter an integer"))
#check for valid input
while num < 1:
num = (int(input("Enter an integer"))
#test for prime
for d in range(2,num):
if (num % d) == 0:
print(num,"is not prime.")
else:
print(num,"is prime.")
#ask again
again = intput("Do you want to play again? (Y/N)")
You are missing a closing parenthesis ) in the two of your following lines. The correct line of code is
num = (int(input("Enter an integer")))
Also, as sheepez mentioned below, your outer brackets are redundant. You can simply use
num = int(input("Enter an integer"))

NameError: name 'grade' is not defined [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I am trying to write a program that will number grade output when the user enters a letter grade. I am getting this error: NameError: name 'grade' is not defined. Can someone tell me what this error means and help me figure out how to fix it. I am new to programming so I am realy lost.
letterGrade = (input("Please enter a letter grade: "))
if grade >= A:
grade == "4.0"
elif grade < A:
grade < "4.0"
print(grade)
It looks like your if statements are checking for the variable grade, but your input is being assigned to letterGrade. You can fix this either by changing your first line to
grade = input("Please enter a letter grade: ")
or change every instance of grade to letterGrade.
Additionally, grade == "4.0" should probably be grade = "4.0"; x == y checks if x is equal to y, whereas x = y sets x equal to y.

Python elif else syntaxError [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
whenever i try to use else and elif i get that error .
x=4
if x>0:
print("positive")
elif x=4:
print("equal")
else:
print("negative")
Msg Error :
File " '<'stdin'>' ", line 1
elif x=4 :
^
SyntaxError: invalid syntax
File "'<'stdin'>'", line 1
else:
^
SyntaxError: invalid syntax
= is an assignment operator.
== is a comparison operator.
You need to use the comparison operator in the elif statement like so:
x = 4
if x > 0:
print("positive")
elif x == 4:
print("equal")
else:
print("negative")
That is because you are using assignment operator = instead of equality operator ==.
x=4
if x>0:
print("positive")
elif x==4:
print("equal")
else:
print("negative")

Categories