Usetutoringspotscode to get 8% OFF on your first order!

  • time icon24/7 online - support@tutoringspots.com
  • phone icon1-316-444-1378 or 44-141-628-6690
  • login iconLogin

Python Programming

Python Programming
!
You!will!be!adding!your!own!functions!to!the!program.!!There!must!not!be!any!variables!used!outside!any!
of!the!functions.!
!
!
If!you!do!not!complete!all!of!the!assignment,!the!marker!will!run!your!program!until!the!program!stops!
running!and!you!will!be!given!the!marks!for!the!parts!of!the!assignment!you!have!completed.!
!
THE)GAME)OF)DIGIT)MEMORY)
The!one!player!game!of!Memory!is!a!game!in!which!all!of!the!digit!pairs!are!laid!face!down!in!random!order!
on!a!surface!and,!each!turn,!the!player!selects!two!of!the!digits!which!are!then!displayed.!!If!the!two!digits!
selected!by!the!player!match,!the!pair!of!digits!remain!visible!and!the!player!continues!with!the!next!turn!
trying!to!match!another!pair!of!digits.!!If!the!digits!don’t!match!the!digits!are!turned!over!and!the!player!
continues!with!the!next!turn.!The!object!of!the!game!is!to!turn!over!all!the!pairs!of!matching!digits!in!as!
few!turns!as!possible.!! !
Add!the!
functions!
required!to!
the!program.!
! 2!
THE)SKELETON)OF)THE)PROGRAM)
The!skeleton!of!the!program!for!the!game!of!Memory!is!shown!below.!!The!play_one_game()!function!
is!complete!and!should!not!be!changed!in!any!way.!!Copy!this!skeleton!into!your!program!file!and!complete!
the!missing!functions.!!Example!output!using!the!completed!program!is!shown!on!the!last!three!pages!of!
this!document.!
import random
#———————————-
# main part of the program
#———————————-
def main():
player_name = get_player_name()
display_title(player_name)
play_one_game(player_name)
#———————————-
# Play one game
#———————————-
def play_one_game(player_name):
hidden_symbol = “-”
digits = get_random_digits()
user_digits = hidden_symbol * len(digits)
cheating_is_on = get_cheating_on_off()
if cheating_is_on:
display_cheating(digits)
turns_so_far = 0
matched_so_far = 0
pairs_guessed = 0
while not user_digits == digits:
display_digits(user_digits, turns_so_far, pairs_guessed)
index1 = get_index_from_player()
digit1 = digits[index1]
display_first_digit(index1 + 1, digit1)
index2 = get_index_from_player()
digit2 = digits[index2]
previous_user_digits = user_digits
user_digits = get_adjusted_digits(user_digits, index1, index2,
digit1, digit2)
turns_so_far += 1
if digit1 == digit2:
pairs_guessed = get_pairs_guessed(user_digits)
else:
display_digits(user_digits, turns_so_far, pairs_guessed)
press_enter_to_continue()
user_digits = previous_user_digits
display_digits(user_digits, turns_so_far, pairs_guessed)
display_game_end_feedback(player_name, turns_so_far)
main()!

You can leave a response, or trackback from your own site.

Leave a Reply

python programming

python programming
CS 61002 Algorithms and Programming I
Lab Assignment 8
Matching DNA
Project Description
This Lab Assignment will give you more experience with while loops and if statements, and give
you an opportunity to work with strings.
The Problem
Scientists measure how closely related a species is by looking at the DNA sequences for key
proteins and seeing how similar/dissimilar they are. If the two sequences of DNA are essentially
the same, the two species are considered to be evolutionarily closer since there is a relationship
between changes and time. This process is called sequence alignment.
Consider the two strings of DNA below:
Species 1: AATAACGAAA
Species 2: AAAACGAAAA
A scientist can change the alignment by assuming that an insertion or deletion, of one of the
bases has occurred. They could make such a change, called an indel for short, to see if it
improves the alignment:
Species 1: AATAACGAAASpecies
2: AA-AACGAAAA
Assuming two indels, marked as two dashes(-), the alignment is greatly improved. The scientist
would assume that two changes happened, one change in each species.
While complex algorithms exist to do sequence alignment, it is also useful to support a
researcher and allow them to do an alignment by hand.
Project Specification
1. You will prompt for two strings. The strings can have any characters you like, but to be
“biological” it should consist of: “A”, “T”, “C”, “G”. The strings do not have to be of the
same length.
2. You will then prompt for one of 3 commands:
a. “a” for add. Add an indel
b. “d” for delete. Delete an indel
c. “s” for score. Score the present alignment
d. “q” for quit. Stop the process.
3. Adding an Indel. When you add an indel, you must prompt for two pieces of
information:
CS 61002 Algorithms and Programming I
a. which string to change
b. at what index (starting at 0) do you wish to place the indel (placement is before
the given index, Error if the index is out of range).
The string should then be modified and a dash(-) added.
4. Delete an Indel: If you can add an indel, you should be able to delete it if it doesn’t do
what you want. Again, you must prompt for two pieces of information
a. which string to change
b. the index (starting at 0) to delete the indel. It is an Error to delete a character
that is not an indel.
5. Scoring. You will report the number of matches and the number of mismatches.
a. Any indel is automatically a mismatch.
b. If one string is shorter than the other, the shorter string is filled out with indels.
c. After you score, you print both strings.
i. Matching characters are printed in lower case. If the user entered upper
case letters, you convert them to lower case on a match.
ii. All mismatches are printed in upper case.
iii. Indels are printed as dashes.

You can leave a response, or trackback from your own site.

Leave a Reply

Powered by WordPress | Designed by: Premium WordPress Themes | Thanks to Themes Gallery, Bromoney and Wordpress Themes