The following function is supposed to count how many times a certain base (represented as a character variable in Python) appears in a dna sequence (represented as a string variable in Python). Tried to execute it, but it does not work
def count2(dna, base= [' 'c', ])
i = 0
for j in range(len(dna)):
if dna[j] == base:
i += 1
return i
dna = input('aaagggtttgct')
print (i)
def count2(dna, base= [ 'c', ]):
i = 0
for j in range(len(dna)):
if dna[j] in base: # corrected == with in as base is list == will compare to list
i += 1
return i
dna = 'aaagggtttgct' #given string input is used for taking string from user
i = count2(dna) # call the fucntion count2 with sequence dna assign it to i
print(i)
# extra test
i = count2(dna, ['g',]) # with different base
print(i)

The following function is supposed to count how many times a certain base (represented as a...
Can someone fix this python program? I'm trying to do three things: Create a function that takes in a string as a parameter. Then create a dictionary of characters to integers, where the integer represents how many times the number of times the character appears in the word. Create a function that takes two lists as parameters and returns the elements they have in common of the two lists. Ask the user to create a list of numbers and keep...
Python code define a function car that takes 'swift' as a parameter function should count how many letters in the string function should return a dictionary where key is lower case alpha caracter and value is the number of times that character appears in sentence. ex- input- that big car is so expensive output- 't':1, 'h':1, 'a':2, 'b':1, 'i':3,......
Paste this code into a new file and find the errors. The most frequent letter in the user_string is H. # Function displays the character that appears most frequently # in the string. If several characters have the same highest # frequency, displays the first character with that frequency. def main(): # Set up local variables count = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' index = 0 frequent = 0 # Receive user input. user_string = 'Who where what why how' for ch...
C++ Create a function called countOccurences that will count how many times a certain number occurs in the array. The function should take an array, a size and a variable, which is what you are searching for. Heres what I got so far: #include <iostream> #include <string> #include <vector> using namespace std; void fillArray(int a[], int size); void printArray(int a[], int size); int countEvens(int ar[], int size); int main() { int ar[10]; fillArray(ar, 10); printArray(ar, 10); ...
Write a Python Code for a Function: you need to come up with code for shift_char. Write the code in a way in which you can shift the character by writing the number of shifts. Use the ASCII code for this. For example in lie 11, the input for char_to shift is r. U shift it by 1 so it becomes s. below is the function def shift_char(char_to_shift, amount_to_shift): ''' shifts any character by moving it a certain amount on...
this python code below is to find the longest common subsequence from two input string !!! however it give me the wrong answer, can any one fix it thanks def lcs(s1, s2): matrix = [["" for x in range(len(s2))] for x in range(len(s1))] for i in range(len(s1)): for j in range(len(s2)): if s1[i] == s2[j]: if i == 0 or j == 0: matrix[i][j] = s1[i] else: matrix[i][j] = matrix[i-1][j-1] + s1[i] else: matrix[i][j] = max(matrix[i-1][j], matrix[i][j-1], key=len) cs =...
In python, please help me fill in these functions given their limitations. Please use for loops. def palindrome(x): """ For a given string, determine if the string is a palindrome. (The same forward and back) Input: String of any size (including empty) Return: Boolean (True if palindrome, False otherwise) Limitation: You must use a loop. Only function allowed to be used is len (if needed). Cannot use "in" besides "for var in container" """ pass def getCount(char, strng): """ Get...
Throughout this script, can you provide helpful comments about how each function works in the script plus it's significance to the alignment process. Also are there any errors in this script or a way to improve this script? Any help would be appreciated. Thank you. THIS IS A PYTHON CODE AND IS IN IT'S FORMAT _ ITS CLEAR! #!/usr/bin/env python # file=input("Please provide fasta file with 2 sequences:") match=float(input('What is the match score?:')) missmatch=float(input('What is the missmatch score?:')) gap=float(input('What is...
in
python and according to this
#Creating class for stack
class My_Stack:
def __init__(self):
self.items = []
def isEmpty(self):
return self.items == []
def Push(self, d):
self.items.append(d)
def Pop(self):
return self.items.pop()
def Display(self):
for i in reversed(self.items):
print(i,end="")
print()
s = My_Stack()
#taking input from user
str = input('Enter your string for palindrome checking:
')
n= len(str)
#Pushing half of the string into stack
for i in range(int(n/2)):
s.Push(str[i])
print("S",end="")
s.Display()
s.Display()
#for the next half checking the upcoming string...