联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp

您当前位置:首页 >> Python编程Python编程

日期:2019-05-21 10:37

CMPS 5P Homework 2 Spring 19

Instructions

1. The aim of this assignment is to practice selection (if, else, and elif) and repetition

structures (while, and for) in Python.

2. The deadline for the assignment is 04/22/2019 (Monday) 11:59 PM.

3. The grade of the assignment is out of 100 pts.

4. Students must use Python3 (NOT Python2) to write the code.

5. Don’t share code or get code from the internet, but working together is encouraged. If

you choose to work with someone you must mention them in one of the first comments

in the file.

6. Students are expected to write the code that is easily readable. To this end, they must

employ meaningful variable names and comment their code properly.

7. The output of the code requires to be precisely as shown in the sample runs.

8. Students must put the code in a file named FirstName LastName StudentID HW2.py

and submit it through Canvas. Please notice that failing to comply any of these requirements

will result in losing points at the discretion of the grader.

Grading The assignment is out of 100 points. It is important that you practice commenting

your code, so each file submitted without comments will have 5 points deducted

from its score (even if the program works perfectly)! Furthermore, the formatting of the

the file names (described in item 8) is important for us to grade all 240 assignments, so

submissions which are not named in this way will have 5 points deducted from their overall

score.

Problem 1

Write a Python3 script which takes in a single stranded DNA sequence from the user and

prints out the ‘GC’ content and molecular weight of the single stranded circular DNA

molecule.

DNA is made up of four nucleotides, thymine (T), cytosine (C), adenine (A), or guanine (G).

These are represented as strings of only A, C, G and T characters of either upper or lower

case).

The program should prompt the user for a DNA sequence. If the provided string is not a

nucleotide sequence (i.e. contains any non A, C, G, T characters of either case), print an

1

CMPS 5P Homework 2 Spring 19

error message and prompt the user for another DNA sequence. NOTE: the program needs

to handle any mixture of upper and lower cases for the DNA sequence!

Once a valid DNA sequence is entered by the user, then calculate the ‘GC content’ - the

fraction of G and C nucleotides in the sequence. For example, if the user entered ’ATGC’

the ’GC’ content would be 50% because the sequence contains 2 G or C nucleotides and 4

characters in total.

Next calculate the total molecular weight of the DNA sequence in Daltons. The given nucleotide

weights for each nucleotide is shown below in Table 1. For example, if the user

entered ‘ATGC’ the molecular weight of the single stranded DNA sequence would be 1235.80

Da.

In detail the following steps should be followed:

1. Prompt user for single stranded DNA sequence with the message

”Input DNA Sequence: ”

2. Check if input contains any characters not in {“T”, “A”, “G”, “C”, “t”, “a”, “g”, “c”}

3. If the user entered an incorrect string, report error:

“ERROR: Not a DNA sequence: user-input-seq”

where user-input-seq is the input sequence, then prompt the user again.

4. Calculate the molecular weight of the single stranded DNA using Table 1.

5. Output the result with

“DNA sequence weighs: weight Da”

and round the weight to the second decimal position

6. Calculate percent of G’s and C’s in the string and report

“GC content of DNA sequence is: percentage”

and round the percentage to the second decimal position.

7. Ask the user if they want to analyze another sequence with the message

“Analyze another DNA Sequence (y/n)?: ”

8. If the user inputs ‘y’ then go through the loop again. If ‘n’, then exit, if neither y nor

n, then ask again.

2

CMPS 5P Homework 2 Spring 19

Table 1: DNA nucleotides’ molecular weights

DNA Nucleotide Molecular weight (Da)

Thymine 304.20

Cytosine 289.18

Adenine 313.21

Guanine 329.21

Example Runs

EXAMPLE 1

Input DNA Sequence: ATGC

DNA sequence weighs: 1235.80 Da

GC content of DNA sequence is: 50.00

Analyze another DNA Sequence (y/n)?: y

Input DNA Sequence: atgc

DNA sequence weighs: 1235.80 Da

GC content of DNA sequence is: 50.00

Analyze another DNA Sequence (y/n)?: n

EXAMPLE 2

Input DNA Sequence: AFtTT!

ERROR: Not a DNA sequence: AFtTT!

Analyze another DNA Sequence (y/n)?: y

Input DNA Sequence: AGTTT

DNA sequence weighs: 1555.02 Da

GC content of DNA sequence is: 20.00

Analyze another DNA Sequence (y/n)?: n

3


版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp