# Untitled

unknown
plain_text
a year ago
3.9 kB
2
Indexable
Never
```import random

points = 0
positive_messages = ['Awesome!', 'Great!','Fantastic!','You got it!']
negative_messages = ['Sorry!', 'That was wrong!']
score_mesaages = ['Score: ', 'Score is: ', 'Your score is: ']

word_bank = ['C' , 'G' , 'A' , 'T']

print("Welcome to the DNA quiz game!")

DNA_length_input = int(input(f"Hi {name_input}, please enter a positive integer for the DNA length >> "))

def generate_sequence(length):
sequence = random.choices(word_bank, k = length)
return ''.join(sequence)

def compute_complement(sequence):
complement_dict = {
'A': 'T',
'T': 'A',
'C': 'G',
'G': 'C'
}
complement = ""
for base in sequence:
complement += complement_dict[base]
return complement

def compute_reverse(sequence_1):
result = ""
for i in s:
result = i + result
return result

def compute_compress(s):
count = 0
compressed_string = ""

for i in range(len(s)):
sequence = s[i]
if i < (len(s) - 1):
hello = s[i + 1]
if hello == sequence:
count += 1
else:
if count == 0:
compressed_string += sequence
else:
compressed_string += f"{count + 1}{sequence}"
count = 0
else:
if count == 0:
compressed_string += sequence
else:
compressed_string += f"{count + 1}{sequence}"
return compressed_string

while True:
if DNA_length_input <= 0:
error_input = int(input("Invalid input, please try again >>> "))
DNA_length_input = error_input
else:
break

option_input = -1
while option_input != 5:
option_input = int(input("\nSelect an option [1-4] to answer a question or 5 to quit the game.\nWin the game by scoring at least 10 points! \n \n1. Complement [2 points]  2. Reverse [2 points] 3. Compress [3 points] 4. Expand [3 points] 5. Quit\n> "))

if option_input >= 1 and option_input <= 5:
if option_input == 1:
sequence = generate_sequence(DNA_length_input)
complement_input = input(f"What is the complement of {sequence}? ").upper()
complement = compute_complement(sequence)

if complement_input == complement:
points += 2
print(random.choice(positive_messages), random.choice(score_mesaages), points)
else:
points -= 1
print (random.choice(negative_messages), "The correct answer is" ,(complement), "You now have" ,(points), "points. \nPlay again?")

if option_input == 2:
sequence_1 = generate_sequence(DNA_length_input)
reverse_input = input(f"What is the reverse of {sequence_1}? ").upper()
s = sequence_1
reverse = compute_reverse(sequence_1)

if reverse_input == reverse:
points += 2
print(random.choice(positive_messages), random.choice(score_mesaages), points)
else:
points -= 1
print (random.choice(negative_messages), "The correct answer is" ,(reverse), "You now have" ,(points), "points. \nPlay again?")
if option_input == 3:
sequence_2 = generate_sequence(DNA_length_input)
compression_input = input(f"What is the compression of {sequence_2}? ").upper()
s = sequence_2
compressed = compute_compress(sequence_2)

if compression_input == compressed:
points += 3
print(random.choice(positive_messages), random.choice(score_mesaages), points)
else:
points -= 1
print (random.choice(negative_messages), "The correct answer is" ,(compressed), "You now have" ,(points), "points. \nPlay again?")
else: