#🔒 Syntax error

57 messages · Page 1 of 1 (latest)

main vapor
#

I don’t know what’s wrong here, can someone explain what I should fix?

oblique parrotBOT
#

@main vapor

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

gusty mortar
#

if statemtns not same level as age

#

put if , elifs back so its same level with variable age

timid elbow
#

Forgot the bracket

#

int(input())

gusty mortar
#

ye that too

timid elbow
#

Not int(input()

deft coyote
main vapor
#

def assignClassroom(age):
age = int(input(' Enter age: ')
if age> 24:
print('Infant room')
elif 24 >= age >= 36:
print('Toddler room')
elif 36 >= age >= 60:
print('Preschool room')
elif age > 60:
print('Kindergarten Prep room')

#

Oh

gusty mortar
#

!code

oblique parrotBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

gusty mortar
#
age = 1
      if ... 
``` this doesnt work needs to be same level as age
#
if ....```
vagrant maple
#

and it will print Infant room always

#

if age> 24 it enters first if clause

flat frigate
#

code is executed from top to bottom – with that in mind, it shouldn't be hard to reason how this will work

waxen kindle
#

what if the age is, let's say, 50?

main vapor
vagrant maple
waxen kindle
flat frigate
#

the indentation causes a syntax error but fixing it doesn't fix the logic flaw

main vapor
#

Alright

#

Wait I made a mistake, the age is supposed to be < 24

flat frigate
#

yeah

main vapor
#

def assignClassroom(age):
age = int(input('Enter age: '))
if age < 24:
print('Infant room')
if 24 >= age >= 36:
print('Toddler room')
if 36 >= age >= 60:
print('Preschool room')
if age > 60:
print('Kindergarten Prep room')

oblique parrotBOT
#

Hey @main vapor!

Please edit your message to use a code block

```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
main vapor
#

How's this?

flat frigate
#
  1. make the latter branches elif 2) you don't have to test for the lower bound of the age
#

the last branch can be else: because age must be >60 anyway at that point

vapid ivy
timid elbow
#

36 > 60 is not valid

flat frigate
#

I don't see 36 > 60 anywhere

#

it's 36 >= age >= 60

#

so 36 >= age and age >= 60

vapid ivy
#

... Actually, I decided to check the website and printed sys.version
3.8.5 (default, Jul 20 2020, 23:11:29) [GCC 9.3.0]

They use a version from 5 years ago, never updated to even patch bugs/security stuff. :x

vapid ivy
flat frigate
#

well, I suggested to convert to elif branches anyway which would make this much easier to read

main vapor
#

It’s still not running 😩

jade lark
#

here's how conditions work:

if thing == othething:
  print("Hi")
elif thing >= 5:
  print("elif happened")
else:
  print("else happened")
main vapor
#

Ok no syntax error now

#

But strangely enough it won’t let me input anything

proper olive
#

run the function assignClassroom()

#

so for instance:

def assignClassroom(age):
age = int(input(' Enter age: '))
if age> 24:
print('Infant room')
elif 24 >= age >= 36:
print('Toddler room')
elif 36 >= age >= 60:
print('Preschool room')
elif age > 60:
print('Kindergarten Prep room')
userInput=int(input("age?:"))
assignClassroom(userInput)

flat frigate
#

so elif age <= 36:

#

because at that point age can only be 24 or above anyway so you don't need to test for that again

flat frigate
proper olive
#

ah mb. i was just thinkng of using the function. afstest way would be removing line 1

oblique parrotBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.