{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Hello World !\n" ] } ], "source": [ "print (\"Hello World !\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A little variable practice..." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "How much gas do you want in your car? It must be less than 11 liters. - 8\n", "Your car has a good amount of fuel!\n" ] } ], "source": [ "# A little variable practice...\n", "d = input(\"How much gas do you want in your car? It must be less than 11 liters. - \")\n", "c = int(d)\n", "if (c >= 7 ):\n", " print (\"Your car has a good amount of fuel!\")\n", "elif (c >= 4 ):\n", " print (\"You might need to fill up your gas tank soon!\")\n", "elif (c >= 1 ):\n", " print (\"Hurry! Fill up now!\")\n", "else:\n", " print (\"Out of fuel!\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Type in an adjective - cool\n", "Type in a noun - monkey\n", "Type in a verb (Past tense) - ran\n" ] } ], "source": [ "#This is my madlib example\n", "adj1 = input(\"Type in an adjective - \")\n", "n1 = input(\"Type in a noun - \")\n", "pverb1 = input(\"Type in a verb (Past tense) - \")\n", "adv1 = input(\"Type in an adverb - \")\n", "adj2 = input(\"Type in an adjective - \")\n", "n2 = input(\"Type in an noun - \")\n", "n3 = input(\"Type in an noun - \")\n", "adj3 = input(\"Type in an adjective - \")\n", "verb1 = input(\"Type in a verb - \")\n", "adv2 = input(\"Type in an adverb - \")\n", "pverb2 = input(\"Type in a verb(Past tense) - \")\n", "adj4 = input(\"Type in an adjective - \")\n", "mymadlib = \"Today I went to the zoo. I saw a %s %s jumping up and down in its tree.He %s %s through the large tunnel that led to its %s %s. I got some peanuts and passed them through the cage to a gigantic gray %s towerng above my head. Feeding that animal made me hungry. I went to get a %s scoop of ice cream.It filled my stomach. Afterwards I had to %s %s to catch the bus.When I got home, I %s my mom about the %s day at the zoo \" %(adj1, n1, pverb1, adv1, adj2, n2, n3, adj3, verb1, adv2,pverb2, adj4)\n", "print (mymadlib)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Do You want to play Trivia? (Y or N) - Y\n", "Okay. What is the capital of the United States of America ? Washington D.C.\n", "Correct!\n", "Next question. What is the tallest mountain in the world ? Mount Everest\n", "Correct!\n", "Alright, next question. What is the largest ocean in the world (Capitalize Ocean) ? Pacific Ocean\n", "Correct !\n" ] } ], "source": [ "#This is my test example\n", "Correct = 0\n", "start = input(\"Do You want to play Trivia? (Y or N) - \")\n", "if (start == \"Y\" ):\n", " Q1 = input (\"Okay. What is the capital of the United States of America ? \")\n", " if (Q1 == \"Washington D.C.\"):\n", " print (\"Correct!\")\n", " Correct = Correct + 1\n", " else:\n", " print (\"Sorry, That's incorrect!\")\n", " Q2 = input (\"Next question. What is the tallest mountain in the world ? \")\n", " if (Q2 == \"Mount Everest\"):\n", " print (\"Correct!\")\n", " Correct = Correct + 1\n", " else:\n", " print (\"Sorry, That's incorrect!\")\n", " Q3 = input (\"Alright, next question. What is the largest ocean in the world (Capitalize Ocean) ? \")\n", " if (Q3 == \"Pacific Ocean\" ):\n", " print (\"Correct !\")\n", " Correct = Correct + 1\n", " else:\n", " print (\"Sorry, That's incorrect !\")\n", " Q4 = input (\"Well, let's continue. What is 8 * 3 ? \")\n", " if ( Q4 == \"24\"):\n", " print(\"Correct!\")\n", " Correct = Correct + 1\n", " else:\n", " print(\"Sorry, That's incorrect!\")\n", " Q5 = input (\"Final question, where is the PyCon 2018 located ? \")\n", " if (Q5 == \"Cleveland\"):\n", " print(\"WooHoo, that's correct!\")\n", " Correct = Correct + 1\n", " else:\n", " print (\"Sorry, that's incorrect!\")\n", " ResultAsk = input (\"Now, are you ready for your score (Y or N) ?\")\n", " if (ResultAsk == \"Y\"):\n", " result = (\"You got %s out of 5 correct! Thanks for trying my trivia!\") %(Correct)\n", " print (result)\n", " else:\n", " print (\"Okay, that's fine! Have a good time!\")" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Hello there. Do you want to try my computer algorithm? (Y or N) - Y\n", "Okay, get ready!\n", "Okay. I will select a random number from 1 to 100. Then, you may take a guess. If my number is higher than yours, I will return 'Higher'. However, if my number is lower than your number, I will send 'Lower'. Are you ready to start ? (Y or N) - Y\n", "Okay. I have selected my number. Which number will you choose?76\n" ] }, { "ename": "TypeError", "evalue": "'<' not supported between instances of 'str' and 'int'", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[0;32mwhile\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 11\u001b[0m \u001b[0mask\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0minput\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;34m\"Okay. I have selected my number. Which number will you choose?\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 12\u001b[0;31m \u001b[0;32mif\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mask\u001b[0m \u001b[0;34m<\u001b[0m \u001b[0mcomNum\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 13\u001b[0m \u001b[0mprint\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;34m\"Sorry, my number is higher than your number.\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 14\u001b[0m \u001b[0mguessNum\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mguessNum\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mTypeError\u001b[0m: '<' not supported between instances of 'str' and 'int'" ] } ], "source": [ "# This is my computer algorithm\n", "start = input (\"Hello there. Do you want to try my computer algorithm? (Y or N) - \")\n", "if (start == \"Y\"):\n", " print (\"Okay, get ready!\")\n", " import random\n", " guessNum = 0\n", " comNum = random.randint (1,100)\n", " myNum = input (\"Okay. I will select a random number from 1 to 100. Then, you may take a guess. If my number is higher than yours, I will return 'Higher'. However, if my number is lower than your number, I will send 'Lower'. Are you ready to start ? (Y or N) - \")\n", " if (myNum == \"Y\"):\n", " while True:\n", " ask = input (\"Okay. I have selected my number. Which number will you choose?\")\n", " if (ask < comNum):\n", " print (\"Sorry, my number is higher than your number.\")\n", " guessNum = guessNum + 1\n", " elif (ask > comNum):\n", " print (\"Sorry, my number is smaller than your number.\")\n", " guessNum = guessNum + 1\n", " else:\n", " Correct = input (\"Correct ! Do you want to play again ? - \")\n", " print(Correct)\n", " guessNum = guessNum + 1\n", " if (Correct == \"Y\"):\n", " \n", " start = input (\"Hello there. Do you want to try my computer algorithm? (Y or N) - \")\n", "if (start == \"Y\"):\n", " print (\"Okay, get ready!\")\n", " import random\n", " guessNum = 0\n", " comNum = random.randint (1,100)\n", " myNum = input (\"Okay. I will select a random number from 1 to 100. Then, you may take a guess. If my number is higher than yours, I will return 'Higher'. However, if my number is lower than your number, I will send 'Lower'. Are you ready to start ? (Y or N) - \")\n", " if (myNum == \"Y\"):\n", " while True:\n", " ask = input (\"Okay. I have selected my number. Which number will you choose?\")\n", " if (ask < comNum):\n", " print (\"Sorry, my number is higher than your number.\")\n", " guessNum = guessNum + 1\n", " elif (ask > comNum):\n", " print (\"Sorry, my number is smaller than your number.\")\n", " guessNum = guessNum + 1\n", " else:\n", " Correct = input (\"Correct ! Do you want to play again ? - \")\n", " print(Correct)\n", " guessNum = guessNum + 1\n", " " ] }, { "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.5.4" } }, "nbformat": 4, "nbformat_minor": 2 }