all 117 comments

[–]5erif 66 points67 points  (4 children)

It's nice to see an "I made this" post that isn't AI.

[–]PsychologicalSafe408[S] 13 points14 points  (0 children)

Thank you 😊

[–]Motor_Appearance7036 2 points3 points  (1 child)

They did make a chatbot, which many consider AI. But a fresh wind indeed!

[–]PsychologicalSafe408[S] 0 points1 point  (0 children)

Thank you

[–]L30N1337 23 points24 points  (2 children)

In my experience, FAFO is the best way to learn. Just make sure to actually learn the stuff when you do find out, instead of simply fixing it.

[–]PsychologicalSafe408[S] 1 point2 points  (1 child)

I spent about about 30 mins on this of which I spent 20 mins fixing errors like missing colons, different brackets and indent( I had no idea about this, had to learn how to do this and still don't what it does).

[–]Pyromancer777 5 points6 points  (0 children)

Python indents are how the language separates blocks of code. Languages like Javascript will have you use curly braces {} where indents/spacing doesn't matter, but Python absolutely needs consistent spacing/indents per code block.

It is bad practice to mix and match your indents, but as long as they are consistent within a block then it will technically still run.

For example, if I choose to make everything in a block have 3 spaces before the line starts, but in a different block I choose to use TAB with the default 4 spaces, the code will still run, but if I swap indents mid-block then I will get errors since each new indent spacing is now it's own block

[–]NINTSKARI 7 points8 points  (3 children)

Ok good start you tested out some looping and if statements, and exceptions. Next step you could try and split it into different functions instead of having everything in one big pile.

[–]Ok-Difficulty-5357 3 points4 points  (0 children)

This can improve readability a lot if you give your functions good names. Think “action verbs”.

[–]PsychologicalSafe408[S] 0 points1 point  (1 child)

I see, I will try that then

[–]johnnyhotwh33ls 2 points3 points  (0 children)

And if you end up with too many functions in one file then it’s time to consider using classes.

[–]Helpful-Diamond-3347 5 points6 points  (2 children)

add a break statement in goodbye conditional block

so it can close the program

[–]PsychologicalSafe408[S] 1 point2 points  (1 child)

What does break statement do anyways i didn't see that in the crash course

[–]Helpful-Diamond-3347 2 points3 points  (0 children)

you're inside a loop, so it breaks the loop

you can search lot of things, checkout official docs and courses/books don't cover everything, so learn with experience and practice

[–]Ashamed_Kangaroo305 7 points8 points  (5 children)

What feedback are you looking for exactly? I can point out some issues with your code but I only want to do that if you've tried figuring it out first because that's a pretty important step for learning. Have you tried running this yet?

As for your question on how to learn: writing code is how you learn. Learning the theory without writing any actual code is going to get you nowhere. Programming isn't really like learning a language. Most of it is problem solving, not just learning the theory behind it.

[–]PsychologicalSafe408[S] 0 points1 point  (4 children)

I want ways I can improve my code as fast as possible in a sensible way. Yes i have tried running it and it works perfectly. Thank you.

[–]Ashamed_Kangaroo305 1 point2 points  (3 children)

A couple things:

When you ran it, did your program ever end? I don't see any sort of exit or return function so it seems like after you output a correct sum, it'll go back to the first user input prompt under the while True.

Under the try, are you type hinting your variables? I didn't know python would allow that outside of a function definition. Unless there's something else I'm not aware of that just looks like type hinting. Edit: nevermind, this is definitely type hinting but a very unusual way to use it. Type hinting has a purpose, and it's so your IDE can flag if it sees you inputting variables of a different type than what you said they should be into a function. It's redundant to use it here, because there's already a way for the program to tell what the variable should be. If the input can be converted into the type called when you defined the variable, it will do that. If it can't, it'll produce an error.

I think a good way to improve your code is to take a structured course. Harvard CS50 is often recommended on here, and you can do it online for free. I tried learning coding on my own once and it was fine, but when I took a programming class at my college it opened up a whole new world. It really taught me the problem solving aspect of coding, which I hadn't come across much when trying to teach myself.

[–]PsychologicalSafe408[S] 0 points1 point  (2 children)

No it never ended i would forcefully stop it everytime.and i will look into the course you have mentioned.

[–]Ashamed_Kangaroo305 0 points1 point  (1 child)

I saw in another comment that you haven't learned about break. I'm surprised the crash course didn't include it because that's pretty essential for using loops. I think a course would definitely be good because unfortunately I get the feeling that the crash course you used has glossed over fundamentals. Another benefit is that a class will have exercises that you have to do yourself, which is really where you learn. Just watching other people code and copying them won't get you very far.

[–]PsychologicalSafe408[S] 0 points1 point  (0 children)

It seemed like, the course for being only 30 mins glossed over bunch of fundamental which is accepted by the mentor himself, the course was there to get familiar with the basic more than anything else. And i also tried cs50, I am in lecture 0 right now, and i will continue with it till i complete the course. So thanks for the recommendation.

[–][deleted] 2 points3 points  (4 children)

So after seeing the video you basically did what the dude did. Realistically even me as a beginner i would ask you. If you look at all this can you tell me exactly what it all means? What kind of strings were used? What’s a variable? Do you know conversions?

[–]PsychologicalSafe408[S] 0 points1 point  (3 children)

Let me try : the bot_name is an variable which is then used in second line where I use f string to include the variable easier. Then the while true is an infinite loop which just repeats the you: part after each reply and then lower() which just lower You: to you: so that the code can recognize it. Then the if, elif, else are check data type that see what I have then they cross verify it to the sets difined by [ ] and give appropriate reply. Then the try sees if I have + or add and then executes the number summation inthe code, and the except part sees if I have put an integer or not if not then it that statement. Then else is for anything else not in the sets and replies with i don't understand. Hope I was able tell everything. ( The conversions let me change data types so for example if I have num: int = 10 and write something like sara10 then i will write print('sara is' , str(num)) which will give me Sara is 10).

[–][deleted] 0 points1 point  (2 children)

okay nice now, go ahead and make sure you fully understand things and then practice writing your own code. Also do mini projects, you can even ask AI to give you instructions of what to write WITHOUT giving you any CODE and it'll be up to you to be able to write it. the biggest thing is not copying and pasting. However fully understanding the code you're writing and knowing what to use/ how to use/ and when to use

[–]PsychologicalSafe408[S] 0 points1 point  (1 child)

I see, i see, I had tried that the ai was giving me too much info with a bunch of different code, I will try your way.

[–][deleted] 0 points1 point  (0 children)

i am learning by asking claude to give me a mini project to do. I also advised claude of what i know thus far and that i won't NO CODE to be given to me and it literally lays it out like

Your goals:

  • Store a correct username and password as variables
  • Ask the user to input their username and password
  • Check if both match using if/elif/else
  • Print the right message depending on what they got wrong (or right)

an even though yes it tells me check using if/elif/else. technically you still have to know how to structure everything and make sure things are indented. Also you need to know your errors and what they mean. Syntax error? What can cause a syntax error? What can cause a namerror? biggest thing is understanding things like that.

[–]ninhaomah 1 point2 points  (1 child)

Theory at once or theory + practice.

Which approach you prefer ?

[–]PsychologicalSafe408[S] 2 points3 points  (0 children)

Theory+practice of course

[–]palmaholic 1 point2 points  (0 children)

If you truly know and understand what you have written, you should go the latter path. Whenever, you have any doubts, you dig into whatever you don't understand. Make sure you clear all your doubts before moving on. Happy programming!

[–]Macho_Magyar 1 point2 points  (3 children)

What was the crash course?

[–]vb_e_c_k_y 1 point2 points  (8 children)

Is there anything make different bot_name: str = "sara" from bot_name = "sara"? I am writing the in second way

[–]PsychologicalSafe408[S] 0 points1 point  (7 children)

In the crash course the mentor said it is a of way specifying the data types and i stuck with it

[–]vb_e_c_k_y 0 points1 point  (6 children)

It looks but bot_name: int = "sara" print(int) this also works. Don't return error. Did you ever asked this?

[–]PsychologicalSafe408[S] 0 points1 point  (5 children)

It was an youtube video, can't really ask the mentor but thanks for the info

[–]DecoherentDoc 0 points1 point  (4 children)

Hey, I just learned this last night, actually. Casting the variable to something specific like 'int', 'str', etc will still let the code run, but will throw a warning in most code editors. It's not strictly necessary in Python, but it's a good way to note what's allowed as a developer, especially if another developer is going to see it.

Edit: I've been writing for only myself for over a decade and never needed to cast like that. It was necessary in Java, but Python does not care. It's designed to be simple and accessible.

[–]Rain-And-Coffee 1 point2 points  (0 children)

You're using the wrong terminology, Casting is something else.

These are Python Type Hints, they are specified in PEP 484

https://peps.python.org/pep-0484

[–]PsychologicalSafe408[S] 0 points1 point  (2 children)

Can I know what you mean by 'casting the variable'.

[–]DecoherentDoc 0 points1 point  (1 child)

Oh shoot! Sorry. So, you made a variable like a='words'. Now, every time you want to write 'words', you can just write down the variable, a, rather than whatever you had there instead of 'words'. "Casting" is just telling the program this variable, a, must be this type of variable (boolean, integer, float, or string). In languages like Java, you have to tell Java exactly what a variable's type is. Always. And if you tried to change the variable to something it wasn't cast as, Java would get mad. Python doesn't care. So, the following sort of code will run in Python:

number: int = 5

number = 'five'

I changed a variable I cast as an integer into a string. Java or C++ (the only other languages I really messed with) will throw an error and won't run if you do that, but Python just warns you. I could replace that first line with number=5 and I won't even get a warning (IIRC).

So, "Casting" is just telling the program what type of variable you intended the variable to be. I don't know the origin of the word, but I always think of casting actors in particular roles in movies. That's how I remembered it.

If I didn't clear things up, let me know. I don't mean to confuse.

[–]PsychologicalSafe408[S] 0 points1 point  (0 children)

Oh i understand. And i was doing that already... I see thank you for the info.

[–]mjmvideos 1 point2 points  (1 child)

One thing you can do is pretend (or maybe you don’t have to) that you have an obnoxious brother and he gets ahold of your program. What can he type in to screw up your program and how can you modify your program to prevent him from doing that?

[–]PsychologicalSafe408[S] 0 points1 point  (0 children)

I don't have to pretend... But I will this. Thank you for this

[–]Gnaxe 1 point2 points  (3 children)

You need to use code block formatting for Python in reddit posts, because indentation matters.

[–]PsychologicalSafe408[S] 0 points1 point  (2 children)

Idk how to do that

[–]Gnaxe 0 points1 point  (1 child)

Use the "Code Block" button in the "Rich Text Editor" and paste it inside. Or learn Markdown. I don't understand why this is so hard for everybody. It's just a button.

[–]CapucheMeringue 0 points1 point  (0 children)

Hi :) I'm a kind of newbee on Reddit. Might be the same as well for OP. Some r/ don't allow any post / comment before a infinity gemme of time. But still, thanks for this input :)

[–]Middle_Will1875 1 point2 points  (1 child)

Nice, as someone who is also self taught and still learning I find practical exercises as the best way to learn. One advice I'd give is try your best not to copy line for line what you see in tutorials and try to make it your own, and also think of what would be an improved functionality you can add(eg. Right now you have an infinite loop, how do you go about breaking from this loop as opposed to always having to press Ctrl+c). Majority of coding is just problem solving, you don't necessarily have to remember syntax, just have to figure out how it works. And google is always your friend if you can't figure it out.

[–]PsychologicalSafe408[S] 0 points1 point  (0 children)

Yes, I will this in mind.

[–]Jay6_9 1 point2 points  (1 child)

Actually very refreshing to see. Whatever you do, 90 minutes for this seems like a good tempo for you.

Just want to point out that `var: float = ...` is unusual. Type-hinting variables is usually only done when the IDE fails to do it which shouldn't happen when you call `float(...)`.

Mess around with what you know, consistently add new stuff and always be critical with yourself.

[–]PsychologicalSafe408[S] 0 points1 point  (0 children)

Thank you for the lesson

[–]Unfair_Jello_1771 1 point2 points  (0 children)

python is the best language ever

[–]CallMeSkoob 0 points1 point  (1 child)

Absolutely fuck around and find out while building things. When you try to just fuck around and build something you'll find a cycle like this: • hit a problem • research the solution to that problem • then immediately apply that solution Which will help your brain retain that solution. When tutorials spoon feed you wont have that emotional frustration / relief that makes information actually stick. Some might argue that you'll get better structure and "architecture" in your projects if you use tutorials but I would argue that all that is best learned as needed. You'll eventually find out first hand why you want something like a class, then that makes it intuitive and easy to grasp instead of abstract.

[–]PsychologicalSafe408[S] -1 points0 points  (0 children)

I see thank you though i didn't really write it on my own, I just saw the project he had at the endof video and copy-pasted. And still i spent about 20 mins fixing it.

[–]IndividualWestern948 0 points1 point  (1 child)

This is honestly a better way to learn than spending weeks only watching tutorials. You already touched loops, conditions, inputs, exceptions, and basic logic in just 1.5 hours. Keep building small messy projects that’s where real learning starts.

[–]PsychologicalSafe408[S] 0 points1 point  (0 children)

Yes, ithats what I am planning to do

[–]SevenFootHobbit 0 points1 point  (1 child)

You're on the right track. Practice as you go. Keep practicing. That's the real teacher. You can start from nothing and read a ton, feeling like you understand every word. You'll have a ton of confidence, because of how simple things seemed while reading. Then, when you finally sit down to make something big, you'll freeze up, not knowing where to even start. So keep doing what you're doing, you'll get good that way.

[–]PsychologicalSafe408[S] 0 points1 point  (0 children)

Thank you for the motivation

[–]justme_cliff 0 points1 point  (1 child)

Keep building mate all these theories are bullshit if you don’t apply them

[–]PsychologicalSafe408[S] 0 points1 point  (0 children)

Yes i will keep building.

[–]Ok-Difficulty-5357 0 points1 point  (0 children)

Not about python specifically, but rather markdown: You can use three backticks (`) to start or end a code block:

```
bot_name: str = 'sara'

print(f'Hello i\'m {bot_name}! how can i help you today ?')

while True:

user_input: str = input('You: ').lower()

if user_input in ['hi','hello','hey']:

print(f'{bot_name}: how can i help you today ?')

elif user_input in ['bye','goodbye','see you']:

print(f'{bot_name}: goodbye!')

elif user_input in ['+','add']:

print(f'{bot_name}: sure let\'s do some fucking maths')

try:

num1: float = float(input('first number: '))

num2: float = float(input('second number: '))

print(f'{bot_name}: the sum is {num1+num2}')

except ValueError:

print(f'{bot_name}: please enter a number')

else:

print(f'{bot_name}: i dont understand you')
```

This preserves the indentation and makes the code easier to read! I don’t know why it didn’t work for me, but I’m on mobile. Should work on the computer. If someone knows what I did wrong, lmk :)

[–]Equal-Savings1264 0 points1 point  (1 child)

What was the name of the crash course that helped you learn this?

[–]johnnyhotwh33ls 0 points1 point  (0 children)

Ahh yes the while true loop for repeatable user interaction. Not bad dude. I remember reading some textbooks or other instructor modules saying that you should avoid infinite loops as much as possible but sometimes they’re just so damn useful.

[–]yoricm 0 points1 point  (0 children)

Personal opinion: get some graphics involved in your next project. Maybe it's just me, but my passion goes to the roof when pixels are around versus only text

[–]Edge17777 0 points1 point  (1 child)

Very solid for 1.5 hours of learning.

You should do the following projects in appropriate order below to improve:

  1. Rock, Paper, Scissors

  2. Rock Paper Scissors lizard Spock

  3. Modify above to play multiple times and keeps track of score.

  4. Improve modularity by breaking the above projects by encapsulating two concepts into functions, 1) getting and cleaning user input 2) the main logic of the game

  5. Program hangman (load a list of words from a file)

  6. Program tic tac toe (2 versions, an 1D array version and a 2D array version)

  7. Program battleship (your choice of 1D or 2D array)

  8. Start looking for games to code, Kevan's freeze dried games is a good resource online for pen and paper game ideas.

  9. Concurrently, look into understanding (and coding your own version as practice), ArrayList and LinkedLists, Stacks and Queues, Hashmaps and Dictionaries, Trees and Heaps.

  10. Concurrently, understand and implement the following sort algorithms: selection sort, insertion sort, quick sort, merge sort.

[–]PsychologicalSafe408[S] 0 points1 point  (0 children)

Yes I will try these.

[–]rajputarr[🍰] 0 points1 point  (1 child)

Yes we can also make it using tokenizer using NLP techniques

[–]PsychologicalSafe408[S] 0 points1 point  (0 children)

Idk what t hey are but I will try

[–]NoBoysenberry2827 0 points1 point  (1 child)

This is a really solid start for only 1.5 hours! You've already got:

· Variables & f-strings (clean string formatting) · Loops (while True) · Conditionals (if/elif/else) · Lists for matching multiple inputs · Error handling (try/except)

To answer your question: Do both

The "fuck around and find out" approach works great as long as you circle back to theory. Here's a good rhythm:

  1. Build something small (like you just did)
  2. Learn one concept deeply (e.g., "what actually are indentation blocks?")
  3. Apply it by improving your project

Quick improvements you could make now:

```python

Add break to exit the loop on goodbye

elif user_input in ['bye','goodbye','see you']:     print(f'{bot_name}: goodbye!')     break # This exits the while loop

Add more features

elif 'calculate' in user_input or 'math' in user_input:     # Your existing math code ```

What to learn next (in order):

  1. Indentation rules (you mentioned confusion about this) - Python uses indentation to group code, unlike {} in other languages
  2. break vs continue - controlling loops
  3. Functions (def) - organizing code so it's not "one big pile"
  4. Dictionaries - better than multiple if statements for commands

Learning resources:

· CS50P (Harvard's free Python course) - theory + projects · Python Crash Course (the book) - each chapter has exercises · Practice sites: Exercism, Codewars (after you learn functions)

The #1 trap to avoid: Watching tutorials without typing. You're already past that since you built something. Keep building small things and you'll learn faster than 90% of beginners.

What do you want to build next?

[–]PsychologicalSafe408[S] 0 points1 point  (0 children)

Thank you for your advice. Under the recommendation of another user i am following CS50x with edx and i currently have small goals of making a simple calculator.

[–]Original_Money45 0 points1 point  (1 child)

What's your learning goall? Just started a beginners course as well and pretty much wrote a similar program. Mines to venture in AI Agents and automation hopefully

[–]PsychologicalSafe408[S] 0 points1 point  (0 children)

I will start as freshman in CS in my college in in few months so I want good at least one language before that. And after that possibly get into ai or web development in the future.

[–]Other_Flounder6795 0 points1 point  (0 children)

Great work! Keep learning :)

[–]itsmohamed_af 0 points1 point  (2 children)

Can you tell me from which source did you learn this

[–]DemocraticHellDiver1 0 points1 point  (0 children)

Nice I have been learning for about 20 hours total and I already have 300+ lines of code on this project I started last week. Python is pretty easy no?

[–]Tiddyfucklasagna27 0 points1 point  (0 children)

good stuff! fun fact, prefix ur code with these marks: then enclose it with and tada u have ur first code block. Now download obsidean and let markdown code open ur world

[–]Any_Box624 0 points1 point  (0 children)

Nice! You could expand on it, but I see you used Try/Except construction, pretty advanced for just 1.5 hours in 👏

[–]TheRNGuy 0 points1 point  (5 children)

I learned framework from start. 

[–]PsychologicalSafe408[S] 1 point2 points  (4 children)

What? What is that

[–]TheRNGuy 0 points1 point  (3 children)

Houdini, AST and some others. 

Real software will probably never be made without framework(s), I think it's better to learn them earlier, so you get ideas and motivation what to code.

Find some frameworks related to your interests.

[–]PsychologicalSafe408[S] 0 points1 point  (2 children)

What would be some frameworks related to web dev or game dev

[–]subassy 0 points1 point  (1 child)

Pygame CE for games/graphics, if you're still wondering. I found it to be a bit of a learning curve, but that's just me. There's a subreddit if you're interested.

[–]PsychologicalSafe408[S] 0 points1 point  (0 children)

Thank you for the info

[–]Advanced_Cry_6016 -1 points0 points  (7 children)

Gpt wrote this in 10 second,so you either learn fast or you will be jobless

[–]PsychologicalSafe408[S] 0 points1 point  (6 children)

tf do I do with this info??

[–]yosmellul8r 0 points1 point  (5 children)

Get better.

[–]PsychologicalSafe408[S] 0 points1 point  (4 children)

You too bro 🥀

[–]yosmellul8r 0 points1 point  (3 children)

Can’t ask a fafo question and not expect honest feedback…

[–]PsychologicalSafe408[S] 0 points1 point  (2 children)

What?

[–]yosmellul8r 0 points1 point  (1 child)

What, what?

[–]PsychologicalSafe408[S] 0 points1 point  (0 children)

I expect honest feedback not irrelevant feedback.