{ "metadata": { "name": "", "signature": "sha256:fe01c82a9918de91a64f11b55092a32ee8f2eb127cb60c15e72a3cd43d5cae26" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## [Python Programming for Biologists, Tel-Aviv University / 0411-3122 / Spring 2015](http://py4life.github.io/TAU2015/)\n", "# Homework 1\n", "\n", "## 1) Mendelian fruit\n", "Mr. Lendem is studying the genetics of odor in Guavas (_Psidium guajava_).He knows that the D gene, controlling odor, follows Mendelian inheritance so that DD Guavas have a strong typical smell, Dd plants have weaker smell and dd plants don't smell at all. \n", "\n", "Write a program that, given a number of Guava plants examined, will calculate and print the expected numbers of smelly, less smelly and non-smelly plants (according to the Mendelian 1:2:1 inheritance law). \n", "- Remember that the expected number of plants is an _integer_!\n", "![guavas](http://www.touilleur-express.fr/wp-content/guava.jpg)" ] }, { "cell_type": "code", "collapsed": false, "input": [ "plants_num = 145 # Replace ??? with a value of your choice.\n", "\n", "smelly = int(0.25*plants_num)\n", "less_smelly = int(0.5*plants_num)\n", "non_smelly = int(0.25*plants_num)\n", "\n", "print('Smelly:',smelly)\n", "print('Less smelly:',less_smelly)\n", "print('Non Smelly:',non_smelly)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Smelly: 36\n", "Less smelly: 72\n", "Non Smelly: 36\n" ] } ], "prompt_number": 1 }, { "cell_type": "markdown", "metadata": {}, "source": [ "b) something similar with two genes..." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 2) Blood types\n", "Each individual has either blood type 'A', 'B', 'AB' or 'O'. \n", "Blood donations may be received from individuals with the same blood type, although 'AB' may receive all types and 'O' may donate to all types. \n", "\n", "Write a program that, given the blood types of two patients, prints whether the recepient may receive a blood donation from the donor. The program should print 'True' if a donation is possible, 'False' if it isn't, and 'Invalid input' if one of the blood types is not 'A', 'B', 'AB' or 'O' (only accept uppercase letters." ] }, { "cell_type": "code", "collapsed": false, "input": [ "recepient_blood_type = 'O' # Replace ??? with a value of your choice.\n", "donor_blood_type = 'B' # Replace ??? with a value of your choice.\n", "\n", "# make sure that input blood types are valid\n", "if (recepient_blood_type != 'A' and recepient_blood_type != 'B' and recepient_blood_type != 'AB' and recepient_blood_type != 'O') \\\n", " or (donor_blood_type != 'A' and donor_blood_type != 'B' and donor_blood_type != 'AB' and donor_blood_type != 'O'):\n", " print (\"Invalid input\")\n", "# if they are valid\n", "else:\n", " # if they same blood type, or recepient is AB or donor is O, donation is OK\n", " if recepient_blood_type == donor_blood_type or recepient_blood_type == 'AB' or donor_blood_type == 'O':\n", " print(True)\n", " # else, donation is not OK\n", " else:\n", " print(False)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "False\n" ] } ], "prompt_number": 4 }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 3) Lab manager\n", "In Dr. Dre's lab, there are X students, each uses Y Petri dishes a day, on average. At the begining of each month, the lab manager has to decide if he/she should order more dishes. Given the number of students (X), the average number of dishes they use per day (Y) and the number of dishes in stock (N), write a program that will make the decision, using the following rules: \n", "- If there are enough dishes for the coming __two__ months, do not order anything. \n", "- If there are enough dishes for the coming month, but not for two month, order the ammount required to complete a two-month stock.\n", "- If there aren't enough dishes for the coming month, complete a two month stock __and__ order another mont's stock for reserves.\n", "\n", "Print the total number of dishes that should be ordered." ] }, { "cell_type": "code", "collapsed": false, "input": [ "students = 6 # Replace ??? with a value of your choice.\n", "dishes_per_student = 65 # Replace ??? with a value of your choice.\n", "dishes_in_stock = 425 # Replace ??? with a value of your choice.\n", "\n", "one_month_supply = students * dishes_per_student\n", "if dishes_in_stock > 2 * one_month_supply:\n", " dishes_to_order = 0\n", "elif one_month_supply < dishes_in_stock < 2 * one_month_supply:\n", " dishes_to_order = 2 * one_month_supply - dishes_in_stock\n", "elif dishes_in_stock < one_month_supply:\n", " dishes_to_order = 3 * one_month_supply - dishes_in_stock\n", "\n", "print('Order',dishes_to_order,'dishes')" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Order 355 dishes\n" ] } ], "prompt_number": 12 } ], "metadata": {} } ] }