Write to a File in Python

To replace the content completely, we use the "r" mode, so we pass this string as the second argument to open(). We call the .write() method on the file object passing the content that we want to write as argument.

For example:

words = ["Blue", "Amazing", "Python", "Code"]

with open("famous_places.txt", "r") as file:
    for word in words:
        file.write(word + "\n")
[mai mult...]

Number Guessing Game with Python

A number guessing game aims to guess the number that the program has come up with.

  1. The program randomly selects a number between 1 and 100
  2. It will then ask the player to enter his proposal.
  3. It will then check if this number is the same as the one generated randomly
  4. If the player’s guess is not the same, then he will check if the number is higher or lower than the guess and tell the player.
[mai mult...]

The Game of Life with Python

The game uses a rectangular grid of cells of infinite size in which each cell is empty or occupied by an organism. The occupied cells are alive, while empty ones are dead. Each turn creating a new generation based on the arrangement of living organisms in the current configuration.

[mai mult...]