• 5 Posts
  • 18 Comments
Joined 1 year ago
cake
Cake day: July 1st, 2023

help-circle










  • I think the other guys have already explained it quite well, but here are some more goodies that might interest you.

    Your first attempt of filling the display is the more pythonic way in my opinion and it works, so instead of initializing an empty array and the filling it, just use display = ["_"]*word_length

    Also for evaluating if the guess is in the word, there is a very nice iterator called enumerate, that hands you two values, the index and the actual value of the item, so you can use it like this:

    for position, letter in enumerate(chosen_word):
        if letter == guess:
            display[position] = letter
    

    Also, to play the full game you want to surround your guessing part with a while loop, so you can keep guessing until you have found the word. For this you will have to create a list of characters that resemble your chosen_word. There are several ways to do so and I will try to explain some of them.

    Here we are using the unpacking asterisk, that unpacks each character of your string into an item in the list

    while (display != [*chosen_word]):
        guess = input("Guess a letter: ").lower()
    
        for position, letter in enumerate(chosen_word):
            if letter == guess:
                display[position] = letter
        print(display)
    

    Another way would be explicitly casting the string into a list with the list function like this:

    while (display != list(chosen_word)):
    

    Last but not least we could use something like list comprehension, which is seen as very pythonic but a bit weird to look at when you are not used to it.

    while (display != [letter for letter in chosen_word]):
    

    What this essentially does is the same as creating a for loop and filling a list like this, but more comprehensive:

    chosen_word_list = []
    for letter in chosen_word:
        chosen_word_list.append(letter)
    

    W3Schools has some nice info about list comprehension. It is a rather advanced concept though so don’t let it bother you if you don’t get it right away.

    Happy coding :)


  • Disagree on this one, even though I can see where you are coming from. I first learnt programming in Java, and it gave me massive problems to understand the structure and typings. Obviously Java isn’t the most beautiful language anyways, but once I picked up python it started to click for me on how to solve problems, because I didn’t have to think about that many things. I could just go for it. Yes, my code was messy in the beginning, but I wasn’t working on any important projects. It was just for fun.

    So I think learning how to solve problems is as important as writing clean code. And python really helped me with that.









  • As much as I like the idea of pointing newcomers into the right direction, post says basically nothing at all. All 5 points can be used for literally everything not specific to coding really.

    Coding and CS in general has become so huge that finding a place to start can be very overwhelming, so just linking some resources won’t do the trick.

    A beginner should ask himself “what do I like to do” which then would point into a direction of what programming language to use. E.g. “I want to automate my daily tasks” would point towards python. Whereas "I want to make own game’ would point towards the unity world and C#. “I want to make my own website” to javascript. And obviously “I want to write almost unreadable loads of boilerplate code” would be java.

    From then on your resources could make sense to explore.

    Also “talk to people” is easier said then done. Most people not in a programmer bubble don’t even have the access, so linking to programming communities would be nice.

    Hope my 2 cents help to make it a bit more concrete




  • This year really was horrible up until mid June I would say. So much that even the farmers can see it in their first harvesting season, it’s way worse than the last year’s because most of the fields were under water. Sorry you got the wrong end of it. But even if the forecast ist supposed to be good it can all change really quickly up here. Still amazing to visit :)