-
Поиграйте в игру:
-
Пример кода (Python): игра «Угадай число»
import random def guess_the_number(): number = random.randint(1, 100) guess = None tries = 0 while guess != number: guess = int(input("Guess a number between 1 and 100: ")) tries += 1 if guess < number: print("Too low!") elif guess > number: print("Too high!") else: print(f"Congratulations! You guessed the number in {tries} tries.") guess_the_number()
-
-
Читать книгу:
-
Пример кода (Python): программа чтения текстовых файлов
def read_book(filename): with open(filename, 'r') as file: content = file.read() print(content) read_book('book.txt')
-
-
Посмотрите фильм или телепередачу:
-
Пример кода (Python): рекомендатель фильмов
import random def recommend_movie(): movies = ['Movie 1', 'Movie 2', 'Movie 3', 'Movie 4', 'Movie 5'] movie = random.choice(movies) print(f"I recommend you watch: {movie}") recommend_movie()
-
-
Узнайте что-то новое:
-
Пример кода (Python): основные математические операции
def perform_math_operation(operation, num1, num2): if operation == '+': result = num1 + num2 elif operation == '-': result = num1 - num2 elif operation == '*': result = num1 * num2 elif operation == '/': result = num1 / num2 else: return "Invalid operation" return result print(perform_math_operation('+', 5, 3)) # Output: 8
-
-
Прогуляйтесь или займитесь спортом:
-
Пример кода (Python): счетчик шагов
steps = 0 def increment_steps(): global steps steps += 1 increment_steps() print(f"Total steps: {steps}")
-
-
Займитесь хобби или творческой деятельностью:
-
Пример кода (Python): программа рисования с использованием графики Turtle
import turtle def draw_square(): turtle.forward(100) turtle.right(90) turtle.forward(100) turtle.right(90) turtle.forward(100) turtle.right(90) turtle.forward(100) draw_square()
-
-
Попробуйте новый рецепт и приготовьте что-нибудь:
-
Пример кода (Python): генератор рецептов
import random def generate_recipe(): recipes = ['Recipe 1', 'Recipe 2', 'Recipe 3', 'Recipe 4', 'Recipe 5'] recipe = random.choice(recipes) print(f"Today's recipe: {recipe}") generate_recipe()
-
-
Решайте головоломки и головоломки:
-
Пример кода (Python): решатель судоку
def solve_sudoku(board): # Sudoku solving logic pass board = [[5, 3, 0, 0, 7, 0, 0, 0, 0], [6, 0, 0, 1, 9, 5, 0, 0, 0], [0, 9, 8, 0, 0, 0, 0, 6, 0], [8, 0, 0, 0, 6, 0, 0, 0, 3], [4, 0, 0, 8, 0, 3, 0, 0, 1], [7, 0, 0, 0, 2, 0, 0, 0, 6], [0, 6, 0, 0, 0, 0, 2, 8, 0], [0, 0, 0, 4, 1, 9, 0, 0, 5], [0, 0, 0, 0, 8, 0, 0, 7, 9]] solve_sudoku(board)
-
-
Поиграйте в игру:
-
Пример кода (Python): игра «Угадай число»
import random def guess_the_number(): number = random.randint(1, 100) guess = None tries = 0 while guess != number: guess = int(input("Guess a number between 1 and 100: ")) tries += 1 if guess < number: print("Too low!") elif guess > number: print("Too high!") else: print(f"Congratulations! You guessed the number in {tries} tries.") guess_the_number()
-
-
Читать книгу:
-
Пример кода (Python): программа чтения текстовых файлов
def read_book(filename): with open(filename, 'r') as file: content = file.read() print(content) read_book('book.txt')
-
-
Посмотрите фильм или телепередачу:
-
Пример кода (Python): рекомендатель фильмов
import random def recommend_movie(): movies = ['Movie 1', 'Movie 2', 'Movie 3', 'Movie 4', 'Movie 5'] movie = random.choice(movies) print(f"I recommend you watch: {movie}") recommend_movie()
-
-
Узнайте что-то новое:
-
Пример кода (Python): основные математические операции
def perform_math_operation(operation, num1, num2): if operation == '+': result = num1 + num2 elif operation == '-': result = num1 - num2 elif operation == '*': result = num1 * num2 elif operation == '/': result = num1 / num2 else: return "Invalid operation" return result print(perform_math_operation('+', 5, 3)) # Output: 8
-
-
Прогуляйтесь или займитесь спортом:
-
Пример кода (Python): счетчик шагов
steps = 0 def increment_steps(): global steps steps += 1 increment_steps() print(f"Total steps: {steps}")
-
-
Займитесь хобби или творческой деятельностью:
-
Пример кода (Python): программа рисования с использованием графики Turtle
import turtle def draw_square(): turtle.forward(100) turtle.right(90) turtle.forward(100) turtle.right(90) turtle.forward(100) turtle.right(90) turtle.forward(100) draw_square()
-
-
Попробуйте новый рецепт и приготовьте что-нибудь:
-
Пример кода (Python): генератор рецептов
import random def generate_recipe(): recipes = ['Recipe 1', 'Recipe 2', 'Recipe 3', 'Recipe 4', 'Recipe 5'] recipe = random.choice(recipes) print(f"Today's recipe: {recipe}") generate_recipe()
-
-
Решайте головоломки и головоломки:
-
Пример кода (Python): решатель судоку
def solve_sudoku(board): # Sudoku solving logic pass board = [[5, 3, 0, 0, 7, 0, 0, 0, 0], [6, 0, 0, 1, 9, 5, 0, 0, 0], [0, 9, 8, 0, 0, 0, 0, 6, 0], [8, 0, 0, 0, 6, 0, 0, 0, 3], [4, 0, 0, 8, 0, 3, 0, 0, 1], [7, 0, 0, 0, 2, 0, 0, 0, 6], [0, 6, 0, 0, 0, 0, 2, 8, 0], [0, 0, 0, 4, 1, 9, 0, 0, 5], [0, 0, 0, 0, 8, 0, 0, 7, 9]] solve_sudoku(board)
-