Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,337 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"id": "Acnj71h-cJ6q",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "b7e6ef72-4462-44b1-ef84-075b21bad469"
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"False\n",
"True\n",
"False\n",
"True\n",
"False\n",
"True\n"
]
}
],
"source": [
"numbers: list = [print(n % 2 != 0) for n in range(0,6)]"
]
},
{
"cell_type": "code",
"source": [
"print(numbers)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "j00c1ru7OrIv",
"outputId": "0736482b-1f00-465d-fcc3-75dcb3e66ed9"
},
"execution_count": 2,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"[None, None, None, None, None]\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"# odd_n = []"
],
"metadata": {
"id": "m2AnhkqQPI3V"
},
"execution_count": 15,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# for n in range(1, 6):\n",
"# if n % 2 != 0:\n",
"# odd_n.append(n)\n",
"# else:\n",
"# even_numbers = [n]\n",
"\n",
"# print(odd_n)\n",
"# print(even_numbers)"
],
"metadata": {
"id": "sfljUxooOtrD"
},
"execution_count": 14,
"outputs": []
},
{
"cell_type": "code",
"source": [
"odd_n: list = []\n",
"\n",
"for n in range(1, 6):\n",
" if n % 2 != 0: odd_n.append(n)\n",
"\n",
"print(odd_n)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "rCsrPngROx4Q",
"outputId": "a84a372a-1320-48a1-b6d2-4d90f8fc532b"
},
"execution_count": 18,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"[1, 3, 5]\n"
]
}
]
},
{
"cell_type": "code",
"source": [],
"metadata": {
"id": "EBHH5k93pz4f"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"for n in range(0 , 1):\n",
" if n % 2 == 0:\n",
" print('Is Even')\n",
" else: print('Is odd')\n",
""
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "ghpUWAWgPlNN",
"outputId": "d6af0657-d84f-43b5-f468-02ff690f3f85"
},
"execution_count": 19,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Is Even\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"def check_even_odd() -> int:\n",
" for n in range(0, 1):\n",
" 'Is Even' if n % 2 ==0 else 'Is Odd'"
],
"metadata": {
"id": "4C0NObxxp5I7"
},
"execution_count": 21,
"outputs": []
},
{
"cell_type": "code",
"source": [
"def check_even_odd(x: int , y: int) -> str:\n",
" return 'Is Even' if (x & y % 2 == 0) else 'Is Odd'"
],
"metadata": {
"id": "kC5oH5-lqobx"
},
"execution_count": 23,
"outputs": []
},
{
"cell_type": "code",
"source": [
"print(check_even_odd(12 , 2))\n",
"print(check_even_odd(34 , 21))\n",
"print(check_even_odd(21 , 45))"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "75RMtnROq_jh",
"outputId": "df91ba05-eb3f-4e98-ddc5-c9b5255c7be6"
},
"execution_count": 29,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Is Even\n",
"Is Even\n",
"Is Odd\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"def check_even_n(start: int , end: int) -> None:\n",
" for num in range(start , end + 1):\n",
" if num % 2 == 0:\n",
" print(f' Is Even: {num}')\n",
" else: print(f'Is odd: {num}')\n",
"\n",
"print(check_even_n(3 , 21))"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "N8HEjoV3rBsG",
"outputId": "f6e24bc6-885a-49bf-d052-5832343dce68"
},
"execution_count": 33,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Is odd: 3\n",
" Is Even: 4\n",
"Is odd: 5\n",
" Is Even: 6\n",
"Is odd: 7\n",
" Is Even: 8\n",
"Is odd: 9\n",
" Is Even: 10\n",
"Is odd: 11\n",
" Is Even: 12\n",
"Is odd: 13\n",
" Is Even: 14\n",
"Is odd: 15\n",
" Is Even: 16\n",
"Is odd: 17\n",
" Is Even: 18\n",
"Is odd: 19\n",
" Is Even: 20\n",
"Is odd: 21\n",
"None\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"def check_even_n(start: int , end: int) -> None:\n",
" return [f'is Even {num}' if num % 2 == 0 else f'Is Odd: {num}' for num in range(start , end + 1)]\n",
"\n",
"print(check_even_n(1 , 21))"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "tI7XdjoGrwXC",
"outputId": "06f42567-5db4-4425-9ad2-e0ec5ab2e87e"
},
"execution_count": 40,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"['Is Odd: 1', 'is Even 2', 'Is Odd: 3', 'is Even 4', 'Is Odd: 5', 'is Even 6', 'Is Odd: 7', 'is Even 8', 'Is Odd: 9', 'is Even 10', 'Is Odd: 11', 'is Even 12', 'Is Odd: 13', 'is Even 14', 'Is Odd: 15', 'is Even 16', 'Is Odd: 17', 'is Even 18', 'Is Odd: 19', 'is Even 20', 'Is Odd: 21']\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"result = check_even_n(3, 17)\n",
"\n",
"for i in result:\n",
" print(i)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "dv9RXbFcsKMt",
"outputId": "3ca9b051-0f41-40f6-9d61-2846da1f82a9"
},
"execution_count": 42,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Is Odd: 3\n",
"is Even 4\n",
"Is Odd: 5\n",
"is Even 6\n",
"Is Odd: 7\n",
"is Even 8\n",
"Is Odd: 9\n",
"is Even 10\n",
"Is Odd: 11\n",
"is Even 12\n",
"Is Odd: 13\n",
"is Even 14\n",
"Is Odd: 15\n",
"is Even 16\n",
"Is Odd: 17\n"
]
}
]
},
{
"cell_type": "code",
"source": [],
"metadata": {
"id": "rEXmyQ4otUzj"
},
"execution_count": null,
"outputs": []
}
]
}