Computer science project
{ "cells": [ { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from random import choice, randint" ] }, { "cell_type": "code", "execution_count": 47, "metadata": { "collapsed": false }, "outputs": [], "source": [ "#Input, string in format of 12hr time: '4:30 PM'\n", "#Output, string in format of 24hr time: '1630'\n", "def military(time):\n", " hours = int(time[:-6])\n", " minutes = time[-5:-3]\n", " meridian = time[-2:]\n", " if hours < 12 and meridian == 'PM':\n", " hours = str(hours + 12)\n", " elif hours == 12 and meridian == 'AM':\n", " if minutes == '00':\n", " hours = '24'\n", " else:\n", " hours = '00'\n", " else:\n", " hours = str(hours)\n", " #print('else')\n", " if len(hours) < 2:\n", " hours = '0' + hours\n", " return hours + minutes" ] }, { "cell_type": "code", "execution_count": 48, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "else\n", "0200\n" ] } ], "source": [ "#time_2 = '12:15 PM'\n", "#print(military(time_2))\n", "time_3 = '2:00 AM'\n", "print(military(time_3))" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "\n", "time_4 = '12:15 AM'\n", "time_5 = '10:30 AM'\n", "time_6 = '02:30 AM'" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "False\n", "<class 'bool'>\n" ] } ], "source": [ "#scratch work\n", "hours = 2\n", "is_12 = (hours == 12)\n", "print(is_12)\n", "print(type(is_12))" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "if block\n", "13\n" ] } ], "source": [ "#scratch work\n", "hours = 1\n", "meridian = 'PM'\n", "if hours < 12 and meridian == 'PM':\n", " hours = hours + 12\n", " print('if block')\n", "print(hours)" ] }, { "cell_type": "code", "execution_count": 28, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "if block\n", "second if block\n", "24\n" ] } ], "source": [ "#scratch work\n", "hours = 12\n", "minutes = '00'\n", "meridian = 'AM'\n", "if hours == 12 and meridian == 'AM':\n", " print('if block')\n", " if minutes == '00':\n", " hours = '24'\n", " print('second if block')\n", " else:\n", " hours = '00'\n", "print(hours)" ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def random_mutation(DNA):\n", " position = random.randint(0, len(DNA))\n", " base = random.choice('ACTG') \n", " return DNA[:position] + base + DNA[position:]" ] }, { "cell_type": "code", "execution_count": 30, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "AT\n" ] } ], "source": [ "DNA = 'AT'\n", "mutant = random_mutation_better(DNA)\n", "print(mutant)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def random_mutation_better(DNA):\n", " position = random.randint(0, len(DNA)-1)\n", " #Fix this so that it only chooses from the appropriate bases\n", " #There's other mistakes in here too....\n", " #print(position)\n", " if position == 'A':\n", " base = random.choice('CTG')\n", " if position == 'C':\n", " base = random.choice('TGA')\n", " if position == 'G':\n", " base = random.choice('ATC')\n", " else:\n", " base = random.choice('GAC')\n", " #print(base)\n", " return DNA[:position] + base + DNA[position+1:]" ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "C\n" ] } ], "source": [ "DNA = 'A'\n", "mutant = random_mutation_better(DNA)\n", "print(mutant)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def is_mutated(DNA, DNA2):\n", " return DNA != DNA2" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "DNA = 'AT'\n", "mutant = random_mutation_better(DNA)\n", "print(mutant)" ] } ], "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.6.0" } }, "nbformat": 4, "nbformat_minor": 2 }