|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 2, |
| 6 | + "metadata": {}, |
| 7 | + "outputs": [ |
| 8 | + { |
| 9 | + "name": "stdout", |
| 10 | + "output_type": "stream", |
| 11 | + "text": [ |
| 12 | + "***Game of Guess***\n", |
| 13 | + "Hello! \n", |
| 14 | + "Would you like to play a guess game? \n", |
| 15 | + "Enter y/n : y\n", |
| 16 | + "Enter how many games would you like to play :1\n", |
| 17 | + "I am going to think a number between 1-25\n", |
| 18 | + "Guess a number between 1-25 : 12\n", |
| 19 | + "your selction is high\n", |
| 20 | + "Wrong, try again: 8\n", |
| 21 | + "your selction is high\n", |
| 22 | + "Wrong, try again: 4\n", |
| 23 | + "you selection is low\n", |
| 24 | + "Wrong, try again: 6\n", |
| 25 | + "Your guess is correct\n", |
| 26 | + "\n", |
| 27 | + "The number was 6\n", |
| 28 | + "No of tries: 4\n" |
| 29 | + ] |
| 30 | + } |
| 31 | + ], |
| 32 | + "source": [ |
| 33 | + "#Game of Guess\n", |
| 34 | + "\n", |
| 35 | + "\"\"\"\n", |
| 36 | + "Write a programme where the computer randomly generates a number between 0 and 20. The user needs to guess what the number is. If the user guesses wrong,\n", |
| 37 | + "tell them their guess is either too high, or too low. This will get you started with the random library if you haven't already used it.\n", |
| 38 | + "\"\"\"\n", |
| 39 | + "\n", |
| 40 | + "# Import Random\n", |
| 41 | + "\"\"\"\n", |
| 42 | + "If we wanted a random integer, we can use the randint function\n", |
| 43 | + "\n", |
| 44 | + "Randint accepts two parameters: a lowest and a highest number.\n", |
| 45 | + "\n", |
| 46 | + "Generate integers between 1,5. The first value should be less than the second.\n", |
| 47 | + "\"\"\"\n", |
| 48 | + "import random\n", |
| 49 | + "\n", |
| 50 | + "print(\"***Game of Guess***\")\n", |
| 51 | + "\n", |
| 52 | + "question = input(\"Hello! \\nWould you like to play a guess game? \\nEnter y/n : \")\n", |
| 53 | + "\n", |
| 54 | + "tries = 1\n", |
| 55 | + "\n", |
| 56 | + "if question == 'y' or question == 'Y':\n", |
| 57 | + "\n", |
| 58 | + " howmany = int(input(\"Enter how many games would you like to play :\"))\n", |
| 59 | + "\n", |
| 60 | + " for game in range(howmany):\n", |
| 61 | + "\n", |
| 62 | + " print(\"I am going to think a number between 1-25\")\n", |
| 63 | + " number = random.randint(1, 26)\n", |
| 64 | + " guess = int(input(\"Guess a number between 1-25 : \"))\n", |
| 65 | + "\n", |
| 66 | + " # This loop runs until guess mathches with Actual number\n", |
| 67 | + " while guess != number:\n", |
| 68 | + "\n", |
| 69 | + " # Inform User about his/her Guess number selection, to select precisely\n", |
| 70 | + " if guess > number:\n", |
| 71 | + " print(\"your selction is high\")\n", |
| 72 | + "\n", |
| 73 | + " else:\n", |
| 74 | + " print(\"you selection is low\")\n", |
| 75 | + "\n", |
| 76 | + " guess = int(input(\"Wrong, try again: \"))\n", |
| 77 | + "\n", |
| 78 | + " # Tries incremented if guessed number was a wrong one\n", |
| 79 | + " tries += 1\n", |
| 80 | + "\n", |
| 81 | + " if number == guess:\n", |
| 82 | + " print(\"Your guess is correct\\n\")\n", |
| 83 | + " print(\"The number was \", number)\n", |
| 84 | + " print(\"No of tries:\", tries)\n", |
| 85 | + "\n", |
| 86 | + "else:\n", |
| 87 | + " print(\"Okay\")\n" |
| 88 | + ] |
| 89 | + }, |
| 90 | + { |
| 91 | + "cell_type": "code", |
| 92 | + "execution_count": 7, |
| 93 | + "metadata": {}, |
| 94 | + "outputs": [ |
| 95 | + { |
| 96 | + "name": "stdout", |
| 97 | + "output_type": "stream", |
| 98 | + "text": [ |
| 99 | + "----Rock, Paper, Scissors Game----\n", |
| 100 | + "How many times would you like to play this game ? :2\n", |
| 101 | + "Enter your choice :Paper\n", |
| 102 | + "you win~ Paper cover Rock\n", |
| 103 | + "Enter your choice :Rock\n", |
| 104 | + "you win~ Rock smash Scissors\n", |
| 105 | + "----Game Ends-----\n" |
| 106 | + ] |
| 107 | + } |
| 108 | + ], |
| 109 | + "source": [ |
| 110 | + "\"\"\"\n", |
| 111 | + "Rock, Paper, Scissors Game\n", |
| 112 | + "Make a rock-paper-scissors game where it is the player vs the computer. The computer’s answer will be randomly generated, while the program will ask the user for their input. \n", |
| 113 | + "This project will better your understanding of while loops and if statements.\n", |
| 114 | + "\"\"\"\n", |
| 115 | + "\n", |
| 116 | + "import random\n", |
| 117 | + "\n", |
| 118 | + "print('----Rock, Paper, Scissors Game----')\n", |
| 119 | + "\n", |
| 120 | + "choice = [\"Rock\", \"Paper\", \"Scissors\"]\n", |
| 121 | + "\n", |
| 122 | + "howmany = int(input('How many times would you like to play this game ? :'))\n", |
| 123 | + "\n", |
| 124 | + "iterations = 0\n", |
| 125 | + "\n", |
| 126 | + "while iterations < howmany:\n", |
| 127 | + " \n", |
| 128 | + " player = input('Enter your choice :')\n", |
| 129 | + " \n", |
| 130 | + " computer = choice[random.randint(0,2)]\n", |
| 131 | + " \n", |
| 132 | + " if player == computer:\n", |
| 133 | + " print('Tie')\n", |
| 134 | + " \n", |
| 135 | + " elif player == 'Paper':\n", |
| 136 | + " if computer == 'Scissors':\n", |
| 137 | + " print('you lose~',computer,'cuts',player)\n", |
| 138 | + " else:\n", |
| 139 | + " print('you win~',player,'cover',computer)\n", |
| 140 | + " \n", |
| 141 | + " elif player == 'Scissors':\n", |
| 142 | + " if computer == 'Rock':\n", |
| 143 | + " print('you lose~',computer,'smash',player)\n", |
| 144 | + " else:\n", |
| 145 | + " print('you win~',palyer,'cuts',computer)\n", |
| 146 | + " \n", |
| 147 | + " elif player == 'Rock':\n", |
| 148 | + " if computer == 'Paper':\n", |
| 149 | + " print('you lose~',computer,'covers',player)\n", |
| 150 | + " else:\n", |
| 151 | + " print('you win~',player,'smash',computer)\n", |
| 152 | + " \n", |
| 153 | + " else:\n", |
| 154 | + " print('Enter valid choices')\n", |
| 155 | + "\n", |
| 156 | + " iterations = iterations + 1\n", |
| 157 | + " \n", |
| 158 | + "print('----Game Ends-----')\n" |
| 159 | + ] |
| 160 | + }, |
| 161 | + { |
| 162 | + "cell_type": "code", |
| 163 | + "execution_count": null, |
| 164 | + "metadata": {}, |
| 165 | + "outputs": [], |
| 166 | + "source": [] |
| 167 | + } |
| 168 | + ], |
| 169 | + "metadata": { |
| 170 | + "kernelspec": { |
| 171 | + "display_name": "Python 3", |
| 172 | + "language": "python", |
| 173 | + "name": "python3" |
| 174 | + }, |
| 175 | + "language_info": { |
| 176 | + "codemirror_mode": { |
| 177 | + "name": "ipython", |
| 178 | + "version": 3 |
| 179 | + }, |
| 180 | + "file_extension": ".py", |
| 181 | + "mimetype": "text/x-python", |
| 182 | + "name": "python", |
| 183 | + "nbconvert_exporter": "python", |
| 184 | + "pygments_lexer": "ipython3", |
| 185 | + "version": "3.7.4" |
| 186 | + } |
| 187 | + }, |
| 188 | + "nbformat": 4, |
| 189 | + "nbformat_minor": 2 |
| 190 | +} |
0 commit comments