In: Computer Science
Develop the following code in such a manner that it shoulde be having extra 3 attempts(for wrong answrs) for all questions if the user entered wrong answer · for ex: If the user entered correct answer for first question #then 3 attempts will be carried to next questions. If the user entered 3 times wrong answer in 1st question itself means it sholud display as no more attempts and you got o out of 3
code....................
score=0
total_attempts=3
def question1(total_attempts,score):
print('What colors are apples?\na) Red/Green\nb) Orange\n')
answer1=input('enter answer: ')
if(answer1=='a'):
score=score+1
else:
print('try again')
attempts-=1
if attempts<=0:
print(' No More Attempts')
else:
question1(total_attempts,score)
return attempts,score
def question2 (total_attempts,score):
print('What colors are bananas?\na) Red/Green\nb) Yellow\n')
answer1=input('enter answer: ')
if(answer1=='b'):
score=score+1
else:
print('try again')
attempts-=1
if attempts<=0:
print(' No More Attempts')
else:
question2(attempts,score)
return attempts,score
def question3 (total_attempts,score):
print('What is the color of your hair?\na) Red/Green\nb)
Black\n')
answer1=input('enter answer: ')
if(answer1=='b'):
score=score+1
else:
print('try again')
attempts-=1
if attempts<=0:
print(' No More Attempts')
else:
question3(total_attempts,score)
return attempts,score
def questions():
kk=question1(total_attempts,score)
if attempts>0:
hh=question2(kk[0],kk[1])
if attempts>0:
q=question3(hh[0],hh[1])
print('score= ',q[1])
python
score=0
total_attempts=3
list=[3,0]
def question1(total_attempts,score):
print('What colors are apples?\na) Red/Green\nb) Orange\n')
answer1=input('enter answer: ')
if(answer1=='a'):
score=score+1
list[1]=score
elif(total_attempts<=1):
print(' No More Attempts')
list[0]=0
else:
print('try again')
total_attempts=total_attempts-1
list[0]=total_attempts
question1(total_attempts,score)
return list
def question2 (total_attempts,score):
print('What colors are bananas?\na) Red/Green\nb) Yellow\n')
answer1=input('enter answer: ')
if(answer1=='b'):
score=score+1
list[1]=score
elif(total_attempts<=1):
print(' No More Attempts')
list[0]=0
else:
print('try again')
total_attempts=total_attempts-1
list[0]=total_attempts
question2(total_attempts,score)
return list
def question3 (total_attempts,score):
print('What is the color of your hair?\na) Red/Green\nb) Black\n')
answer1=input('enter answer: ')
if(answer1=='b'):
score=score+1
list[1]=score
elif(total_attempts<=1):
print(' No More Attempts')
list[0]=0
else:
print('try again')
total_attempts=total_attempts-1
list[0]=total_attempts
question3(total_attempts,score)
return list
q1=question1(total_attempts,score)
if q1[0]>0:
q2=question2(q1[0],q1[1])
if q2[0]>0:
q3=question3(q2[0],q2[1])
print('score= ',list[1])
the below pics are the screenshots of the program for seeing indendation if you needed
the below are the some output of the screen in different inputs situations
1)if no input is correct
2) if all options are correct
3)if two input options are correct
4) if one option is right and all other wrong answers