#๐ are there any bugs inside of my code? (i dont recommend reading it, it has no comments)
48 messages ยท Page 1 of 1 (latest)
@limber cedar
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 your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/
After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.
I dont believe so
i dont recommend reading it, it has no comments
Comments are really not necessary here. The code is very easy to read, which is great! The only thing that gets in the way is its cyclomatic complexity, but at this level, it doesn't need anything more.
that is the opposite of what people should be doing
no one should be executing/running code that they get from some random person on the internet without understanding the code, especially not after such a statement
huh/
idk i think comments are a thing on pep8
iv never read it tho
its just a quiz thing to help with studying/learning concepts
i said dont read it if you dont want to for a reason. i dont know how messy it is
yeah, i see that
you might want to put the othere strings (and other data) in a data structure too and then loop through them so that you don't have to repeat your code over and over
whats a data structure
a collection of data with a certain structure, which structure depends on the data and the goal of the program
this confuses me
i just started two days ago
you are already constructing simple data structures in the form of tuples right now in the code, but you could make them a little bit more structured and not have to repeat you code so much
for two days in that looks like pretty good progress ๐
side question, are dictionaries just meant for keeping organized code? that way you can just use the key of it and with that get the value
have you programmed in any other language before?
i learned a bit of lua over like a week by just watching tutorials mostly
i already know some basic concepts, and i decided i liked programming recent;y so i decided to learn python
it's to organize information, but you can also affect program flow depending on such information
i wanted to make a chat bot next. would using a dictionary be better then making a bunch of tuples
it looks like you are doing very well so far, keep it up ๐
thanks!!
im going to spend this week learning everything about basic concepts, then i want to try moving on to intermediat stuff
just a "mechanic" chat bot without any intelligence, just prepared a responses, sure you could do that if you want too
alright
do expect the basics to take longer than that though
i want to try giving it combined resposnes, and a limit system so that it doesnt repeat itself after saying one thing once (like hello)
when you have learned dictionaries you might want to see how you could improve the code that you posted earlier so that you don't have to repeat the logic of the script so much
ill try that. i want to optimize everything eventually and add an entirely different part of the quiz for intermediate stuff
also fix the feedback messages
you could even improve this code without using dictionaries (or class of some sort might be even more appropriate)
but without such things the code would get prone to bugs if the data structure isn't exactly what the program expects, and it would be easy to unintentionally get a bug in there
a good exercise would be to build upon this c9de and improve it step by step when you learn new things that you can apply to this code
Anyone else mention that every question responds with either
print("Correct! a conditional is checking if things are (any operator) to other things.")
``` or
```py
print("Wrong! a conditional is checking if things are (any operator) to other things. ")
``` ?
you're right, wrong response strings for all but one question since they are all copy-pasted
So yeah, if you started with some structure like
data = [
{
"question": "What are data types?",
"answers": ["int", "float", "str", ...],
"final": "Data types include int, str, float, ...",
},
...
]
``` then you could have one object per type of question you want to ask, you randomly select that object, and then work from it dynamically.
You don't need to know ahead of time how many possible answers there are per-question, you don't need new variables, and everything stays together.
```py
challenge = random.choice(data)
response = input(challenge["question"])
if response in challenge["answers"]:
result = "Correct!"
else:
result = "Wrong!"
print(f"{result} {challenge['final']}")
Just build on from there, take note of the number of answers you have (len(challenge["answers"])) if you want that, and so on.
This would be my approach to DRYing up the code, as an example. Recognize the patterns that are in the code you have, and distill that down to simpler code with less repetition.
The smaller and less repetitive it is, the more unique features you can have in there.
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.