Архив автора: admin

Python: Problems and Solutions (Chapter 3. Branching, while Loops, and Pseudocode. Guess the Number Game).

We continue to learn programming. After the third chapter in the book: Michael Dawson “We Program in Python”, 2014 (Michael Dawson “Python Programming for the Absolute Beginner”, 3rd Edition), where I studied the features of working with text in the Python programming language, tasks were proposed. Let’s do them together. I will give my solution, and you write your options in the comments.

Program “Guess the number” from Igroglaz without looking at the solution:

import random



guess = ""

guess_num = 0

number = int(random.randint(1,100))



print ("I made a guess: number 1-100. Can you guess it?n")



while guess != number:

    guess = int(input("Enter your proposal: n"))

    if guess > number:

        print("No, it's smaller..n")

    elif guess < number:

        print("No, it's bigger..n")

    else:

        print("Finally, you got it!n")

    guess_num += 1



print ("Number was ", number, ". You guessed it with", 

guess_num, "times. Good job!")

    

input()


By the way, there is a bug in this program in the book. Outside the loop there is tries = 1; whereas it should start from zero.

1) Write a program – a simulator of a “surprise” pie – that would display one of five different “Surprises” at startup, chosen at random.

Читать

Python – показать пользователю результат

Когда мы пишем любую программу на любом языке программирования, то раньше или позже мы хотим, что результат нашего программирования показывался пользователю. Для этого мы используем команду:

print(…) обязательно с маленькой буквы Читать

Python OOP – Object Oriented Programming

We continue to practice programming. After the eighth chapter in the book: Michael Dawson “Programming in Python”, 2014 (Michael Dawson “Python Programming for the Absolute Beginner”, 3rd Edition), where I learned the principles of OOP and program objects / classes, it’s time to move on to practice. Let’s do our homework together!

A Brief Summary of OOP in Python

A program object is a formal representation of a real object in a programming language. Objects are created based on classes.

Читать

Python ООП – объектно-ориентированное программирование

Продолжаем практиковаться в программировании. После восьмой главы в книге: Майкл Доусон “Программируем на Python”, 2014 (Michael Dawson “Python Programming for the Absolute Beginner”, 3rd Edition), где я изучила принципы ООП и программные объекты / классы, пора переходить к практике. Сделаем домашнее задание вместе!

Краткий конспект ООП на Python

Программный объект – формальное представление реального объекта в языке программирования. Объекты создаются на основе классов. Читать

Python: non-standard functions. Game “Tic-tac-toe”.

We continue to learn the Python programming language Python. Let’s move on to chapter 6 “Functions. Tic-Tac-Toe Game” from the book: Michael Dawson “Python Programming”, 2014 (Michael Dawson “Python Programming for the Absolute Beginner”, 3rd Edition) to create our own functions and work with global variables .

How to create a function?

General view of a function in Python: function_name()

To create your own function, you need to declare it.

General form of a function declaration

def function_name(parameter1, parameter2...):

    '''Document string'''

  Function expression block

Читать

Python: нестандартные функции. Игра “Крестики-нолики”.

Продолжаем учить язык программирования пайтон Python. Переходим к изучению 6 главы “Функции. Игра Крестики-нолики” по книге: Майкл Доусон “Программируем на Python”, 2014 (Michael Dawson “Python Programming for the Absolute Beginner”, 3rd Edition), чтобы создавать собственные функции и работать с глобальными переменными.

Как создать функцию?

Общий вид функции в Python: название_функции()

Чтобы создать собственную функцию, нужно ее объявить.

Общий вид объявления функции

def название_функции(параметр1, параметр2...):

    '''Документирующая строка'''

    Блок выражений функции

Читать