bruhbot69
bruhbot69

Reputation: 1

Questions about syntax error and elif function

So I wrote this:

print("Hello There! Welcome 69Bot. What's your name?")
x = input()
print("Hello there, "+x "Are you a student or teacher?")
if input == "student" or "Student":
    print("Welcome! Please enter the class code provided by your teacher:")
elif input == "Teacher" or "teacher":
    print("Welcome! Please enter the class code you would like to go to:")
else:
    print("Please enter a valid option")

However, the first problem is it says invalid syntax on the quotation mark after the

"+x" "print("Hello there, "+x "Are you a student or teacher?")

The second problem is that it automatically assumes you are a student and doesn't take the elif. How can I modify the code so as to fix these two problems? It gives this after you enter your name instead of stopping to see if you entered student or teacher:

Hello there! Are you a student or teacher?
Welcome! Please enter the class code provided by your teacher:

Upvotes: 0

Views: 27

Answers (2)

peanutbutterjlly
peanutbutterjlly

Reputation: 11

The line

print("Hello there, "+x "Are you a student or teacher?")

Should have another plus sign after the variable x since you’re concatenating another string after that.

The second problem is that it automatically assumes you are a student and doesn't take the elif. How can I modify the code so as to fix these two problems? It gives this after you enter your name instead of stopping to see if you entered student or teacher

Your if/elif statements should be checking the variable x, since x holds the input value that the user typed in. For example:

if x == ‘student’: 

Not:

if input == ‘student’

Upvotes: 0

Marko
Marko

Reputation: 779

Your first problem is that you are missing a + after the +x. Like so:

print("Hello there, "+x+"Are you a student or teacher?")

Your second problem is that you are not comparing the input with the "Student". Write it like so:

if x == "student" or x == "Student":

The same goes for "teacher"

Upvotes: 1

Related Questions