Computer science project
{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from random import randint, choice" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "#Input, string in format of 12hr time: '4:30 PM', 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", " if len(hours) < 2:\n", " hours = '0' + hours\n", " return hours + minutes" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def military_2(time):\n", " hours = int(time[:-6])\n", " minutes = time[-5:-3]\n", " meridian = time[-2:]\n", " if hours < 12:\n", " if meridian == 'PM':\n", " return str(hours + 12) + minutes\n", " else:\n", " return '0' + str(hours) + minutes\n", " if hours == 12 and meridian == 'AM':\n", " if minutes == '00':\n", " return '24' + minutes\n", " else:\n", " return '00' + minutes\n", " return str(hours) + minutes" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "print(military_2('4:30 PM'))\n", "print(military_2('4:30 AM'))\n", "print(military_2('12:00 AM'))" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def random_mutation(DNA):\n", " position = random.randint(0, len(DNA)-1)\n", " new_base = random.choice('ACTG') \n", " return DNA[:position] + new_base + DNA[position+1:]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "DNA = 'ACTGC'\n", "#DNA = 'ACTCGGAAGACCCGAGAGCCGAACGGACCGAAGCCCAG'\n", "mutant = random_mutation(DNA)\n", "print(mutant)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "#What is wrong with this? How can you figure it out?\n", "def random_mutation_better(DNA):\n", " position = randint(0, len(DNA)-1)\n", " base = choice('ACGT')\n", " if base == position:\n", " base = choice('ACGT')\n", " return DNA[:position] + base + DNA[position+1:]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "DNA = 'ATTG'\n", "mut = random_mutation_better(DNA)\n", "print(mut)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "original = 'A'\n", "base = choice('AC')\n", "print('base is', base)\n", "if base == original:\n", " base = choice('AC')\n", " print('base is', base)\n", " if base == original:\n", " print('base is', base)\n", " base = choice('AC')\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def convert(amount):\n", " return float(amount[1:])" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "print(convert('$4.50'))" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def money_list(data):\n", " pass" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "a = ['$4.50', '$12.99','$100.50', '$17.25']" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "num = randint(1,100)\n", "guess = int(input('What is your guess? Or enter 0 to quit.'))\n", "while(guess == number or guess != 0):\n", " guess = int(input('What is your guess?'))\n", "print('You got it!')" ] } ], "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.7" } }, "nbformat": 4, "nbformat_minor": 2 }