Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Writing your own functions (2/5) | Functions
Learn Python from Scratch
course content

Зміст курсу

Learn Python from Scratch

Learn Python from Scratch

1. The basics
2. Arithmetic operations
3. Common data types
4. Conditional statements
5. Other data types
6. Loops
7. Functions

Writing your own functions (2/5)

All we have learned till now can be used inside the function. For example, you can easily put conditional statements inside the function body.

For example, we can define a function that will check if the number is odd or even.

12345678910
# define a function def is_odd(n): if n % 2 == 0: return "even" else: return "odd" # testing function print('2 is', is_odd(2)) print('3 is', is_odd(3))
copy

Завдання

Define a function is_positive checking if the number is positive (in that case return positive), negative (return negative), or equals zero (return zero).

Завдання

Define a function is_positive checking if the number is positive (in that case return positive), negative (return negative), or equals zero (return zero).

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів

Все було зрозуміло?

Секція 7. Розділ 3
toggle bottom row

Writing your own functions (2/5)

All we have learned till now can be used inside the function. For example, you can easily put conditional statements inside the function body.

For example, we can define a function that will check if the number is odd or even.

12345678910
# define a function def is_odd(n): if n % 2 == 0: return "even" else: return "odd" # testing function print('2 is', is_odd(2)) print('3 is', is_odd(3))
copy

Завдання

Define a function is_positive checking if the number is positive (in that case return positive), negative (return negative), or equals zero (return zero).

Завдання

Define a function is_positive checking if the number is positive (in that case return positive), negative (return negative), or equals zero (return zero).

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів

Все було зрозуміло?

Секція 7. Розділ 3
toggle bottom row

Writing your own functions (2/5)

All we have learned till now can be used inside the function. For example, you can easily put conditional statements inside the function body.

For example, we can define a function that will check if the number is odd or even.

12345678910
# define a function def is_odd(n): if n % 2 == 0: return "even" else: return "odd" # testing function print('2 is', is_odd(2)) print('3 is', is_odd(3))
copy

Завдання

Define a function is_positive checking if the number is positive (in that case return positive), negative (return negative), or equals zero (return zero).

Завдання

Define a function is_positive checking if the number is positive (in that case return positive), negative (return negative), or equals zero (return zero).

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів

Все було зрозуміло?

All we have learned till now can be used inside the function. For example, you can easily put conditional statements inside the function body.

For example, we can define a function that will check if the number is odd or even.

12345678910
# define a function def is_odd(n): if n % 2 == 0: return "even" else: return "odd" # testing function print('2 is', is_odd(2)) print('3 is', is_odd(3))
copy

Завдання

Define a function is_positive checking if the number is positive (in that case return positive), negative (return negative), or equals zero (return zero).

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Секція 7. Розділ 3
Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
We're sorry to hear that something went wrong. What happened?
some-alt