# Untitled

unknown
plain_text
2 years ago
2.4 kB
1
Indexable
Never
``` import random

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

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 >> "))

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

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

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:
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 (f"That was wrong! 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
complement_1 = compute_reverse(sequence_1)

if reverse_input == complement_1:
points += 2
print(random.choice(positive_messages), random.choice(score_mesaages), points)
else:
points -= 1
print (f"That was wrong! The correct answer is {complement_1} you now have {points} points. \nPlay again?")

```