{ "cells": [ { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 16:52:21) \n", "[Clang 6.0 (clang-600.0.57)]\n", "sys.version_info(major=3, minor=7, micro=3, releaselevel='final', serial=0)\n" ] } ], "source": [ "import sys\n", "import platform\n", "\n", "#Print Python version details\n", "print(sys.version)\n", "print(sys.version_info)\n" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "x86_64\n", "Darwin Kernel Version 19.6.0: Tue Jun 21 21:18:39 PDT 2022; root:xnu-6153.141.66~1/RELEASE_X86_64\n", "Darwin\n", "i386\n" ] } ], "source": [ "#Print details about your computer\n", "\n", "print(platform.machine())\n", "print(platform.version())\n", "print(platform.system())\n", "print(platform.processor())" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "#Write code to print your name" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Brendan Tierney\n" ] } ], "source": [ "print('Brendan Tierney')" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "#Crate a variable containing your name, and print it to the screen" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "My name is Brendan Tierney\n" ] } ], "source": [ "name='Brendan Tierney'\n", "print('My name is ', name)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Enter your name:\n", "brendan\n", "Hello, brendan how are you today?\n" ] } ], "source": [ "#Use the input command to allow a user to enter a value\n", "#for eample, use the input command to ask the use to enter a string\n", "#save the inputted value to a variable\n", "#print the variable\n", "print('Enter your name:')\n", "x = input()\n", "print('Hello, ' + x + ' how are you today?') " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "#Use an IF condition to decide what mesage to print\n", "#Use the input command to ask the use to enter a number\n", "#Use the IF condition to determine if the number if Postive or Negative" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Enter a number :\n", "1\n", "The number 1 is postive\n" ] } ], "source": [ "print('Enter a number :')\n", "x = input()\n", "if int(x) >= 0:\n", " print('The number ', x, ' is postive')\n", "elif int(x) < 0:\n", " print('The number ', x, ' is negative')\n", "else:\n", " print('Unkown number')\n", " " ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "#Add an 'else' condition to the above IF condition\n", "#You can decide what the statement should be, what message should be printed?\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0\n", "1\n", "2\n", "3\n", "4\n" ] } ], "source": [ "#the following will print a range of values\n", "for i in range(0,5):\n", " print(i)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "#Take a copy of this code and paste it into the next cell\n", "#Change the code to add two variables to contain a number, assign a number to these variables\n", "#Change the code in the 'for' loop to print the numbers between the values in the two variables" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "11\n", "12\n", "13\n" ] } ], "source": [ "x = 11\n", "y = 14\n", "for i in range(x, y):\n", " print(i)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "#Take a copy of the code in the previous cell\n", "#Expand it to ask the user to input two values.\n", "#Change the loop to print the values between these two values" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Enter the Start number: \n", "31\n", "Enter the End number: \n", "44\n", "----------\n", "31\n", "32\n", "33\n", "34\n", "35\n", "36\n", "37\n", "38\n", "39\n", "40\n", "41\n", "42\n", "43\n" ] } ], "source": [ "print('Enter the Start number: ')\n", "x = input()\n", "print('Enter the End number: ')\n", "y = input()\n", "print(('----------'))\n", "for i in range(int(x), int(y)):\n", " print(i)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "#what else can you do?" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.3" } }, "nbformat": 4, "nbformat_minor": 4 }