#🔒 Syntax error
57 messages · Page 1 of 1 (latest)
@main vapor
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.
if statemtns not same level as age
put if , elifs back so its same level with variable age
ye that too
Not int(input()
btw it's better to share your code as text and not an image
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
u got the answers
!code
code is executed from top to bottom – with that in mind, it shouldn't be hard to reason how this will work
what if the age is, let's say, 50?
So I’ll need to undo the indent right?
prints Infant room
(didn't ask you though, or are you OP? 😉 )
the indentation causes a syntax error but fixing it doesn't fix the logic flaw
yeah
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')
Hey @main vapor!
```py
print('Hello, world!')
```
This will result in the following:
print('Hello, world!')```
How's this?
- make the latter branches
elif2) 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
Btw, the lack of closing parentheses and how the error looks like means this is Python 3.9 or lower - because error info for missing closing brackets was made better in 3.10 (https://docs.python.org/3/whatsnew/3.10.html#syntaxerrors)
And 3.9 is the current oldest still supported version.
So this website uses either 3.9 or version that is no longer supported... For a "beta" website, that looks very bad.
Invalid rules
36 > 60 is not valid
... 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
Darren means it's logical error, as age can't be higher than 60 and lower than 36 at the same time
well, I suggested to convert to elif branches anyway which would make this much easier to read
you can't have a condition after else
here's how conditions work:
if thing == othething:
print("Hi")
elif thing >= 5:
print("elif happened")
else:
print("else happened")
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)
you still don't need the lower bound checks
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
why ask for the age twice?
ah mb. i was just thinkng of using the function. afstest way would be removing line 1
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.