|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 1, |
| 6 | + "metadata": {}, |
| 7 | + "outputs": [ |
| 8 | + { |
| 9 | + "name": "stdout", |
| 10 | + "output_type": "stream", |
| 11 | + "text": [ |
| 12 | + "You are an adult.\n", |
| 13 | + "Good afternoon!\n", |
| 14 | + "It's hot outside!\n", |
| 15 | + "It's a warm day, perfect for a walk!\n", |
| 16 | + "Welcome to the Number Guessing Game!\n", |
| 17 | + "I have selected a number between 1 and 100. Try to guess it.\n" |
| 18 | + ] |
| 19 | + } |
| 20 | + ], |
| 21 | + "source": [ |
| 22 | + "# Define a variable to store the user's age\n", |
| 23 | + "age = 25\n", |
| 24 | + "\n", |
| 25 | + "# Check if the user is 18 or older\n", |
| 26 | + "if age >= 18:\n", |
| 27 | + " # If the condition is true (age is 18 or older), print the message\n", |
| 28 | + " print(\"You are an adult.\")\n", |
| 29 | + "else:\n", |
| 30 | + " # If the condition is false (age is less than 18), print this message\n", |
| 31 | + " print(\"You are a minor.\")\n", |
| 32 | + " \n", |
| 33 | + "# Another example with more conditions\n", |
| 34 | + "# Let's define a variable for the time of the day (in 24-hour format)\n", |
| 35 | + "time_of_day = 14 # 14 means 2 PM\n", |
| 36 | + "\n", |
| 37 | + "# Check if it's morning, afternoon, or evening\n", |
| 38 | + "if time_of_day < 12:\n", |
| 39 | + " # If the time is less than 12, it's morning\n", |
| 40 | + " print(\"Good morning!\")\n", |
| 41 | + "elif time_of_day < 18:\n", |
| 42 | + " # If the time is less than 18 but 12 or more, it's afternoon\n", |
| 43 | + " print(\"Good afternoon!\")\n", |
| 44 | + "else:\n", |
| 45 | + " # If the time is 18 or more, it's evening\n", |
| 46 | + " print(\"Good evening!\")\n", |
| 47 | + " \n", |
| 48 | + "# Example of a nested if-else statement\n", |
| 49 | + "temperature = 30 # Current temperature in Celsius\n", |
| 50 | + "\n", |
| 51 | + "# Check if it's hot or cold\n", |
| 52 | + "if temperature > 25:\n", |
| 53 | + " print(\"It's hot outside!\")\n", |
| 54 | + " # If it's hot, check if it's too hot to go outside\n", |
| 55 | + " if temperature > 35:\n", |
| 56 | + " print(\"It's too hot to go outside.\")\n", |
| 57 | + " else:\n", |
| 58 | + " print(\"It's a warm day, perfect for a walk!\")\n", |
| 59 | + "else:\n", |
| 60 | + " print(\"It's a cool day.\")\n", |
| 61 | + "\n", |
| 62 | + "\n", |
| 63 | + "\n" |
| 64 | + ] |
| 65 | + } |
| 66 | + ], |
| 67 | + "metadata": { |
| 68 | + "kernelspec": { |
| 69 | + "display_name": "Python 3", |
| 70 | + "language": "python", |
| 71 | + "name": "python3" |
| 72 | + }, |
| 73 | + "language_info": { |
| 74 | + "codemirror_mode": { |
| 75 | + "name": "ipython", |
| 76 | + "version": 3 |
| 77 | + }, |
| 78 | + "file_extension": ".py", |
| 79 | + "mimetype": "text/x-python", |
| 80 | + "name": "python", |
| 81 | + "nbconvert_exporter": "python", |
| 82 | + "pygments_lexer": "ipython3", |
| 83 | + "version": "3.13.1" |
| 84 | + } |
| 85 | + }, |
| 86 | + "nbformat": 4, |
| 87 | + "nbformat_minor": 2 |
| 88 | +} |
0 commit comments