#π Sorting Hat Program
55 messages Β· Page 1 of 1 (latest)
@worn narwhal
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.
oh it said no images
uhh mb
patient = input("Would you describe yourself as being patient?: ").lower()
if patient=="yes":
hufflepuff = hufflepuff + 1
elif patient=="no":
slytherin = slytherin + 1
else:
print("Invalid input. Please enter yes or no.")
Hey @worn narwhal!
```py
print('Hello, world!')
```
This will result in the following:
print('Hello, world!')```
oh what
cool
'''py
patient = input("Would you describe yourself as being patient?: ").lower()
if patient=="yes":
hufflepuff = hufflepuff + 1
elif patient=="no":
slytherin = slytherin + 1
else:
print("Invalid input. Please enter yes or no.")
'''
huh
oh
beside the num 1 key
`
coolty
patient = input("Would you describe yourself as being patient?: ").lower()
if patient=="yes":
hufflepuff = hufflepuff + 1
elif patient=="no":
slytherin = slytherin + 1
else:
print("Invalid input. Please enter yes or no.")
WHOA
awesome
anyways
how can i make it reask the question
you need a loop
and a break under the if and elif
yes
you could write a function for it
you should
lol
okok thanks
This: slytherin = slytherin + 1
can be written: slytherin += 1
which avoids repeating the variable name.
Probably worth writing a yesno(prompt) function which issues the prompt using input(), checks for a yes/no and returns True or False accordingly, and complains for other inputs (and maybe asks again, and again).
well
Then you can go:
if yesno("Would you describe yourself as patient?: "):
hufflepuff += 1
else:
slytherin += 1
i wrote the code, it works how i want it to, its 110 lines somy teacher will count it so i should be alr
ohhh
thats
yeah
i think the teacher will complain if i start using stuff that we have not learnt yet
This is why functions are nice. You can put that same repeated ogic in one .
Maybe so.
he complained when i used if statements in the first unit
but thank you for your help
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.