Question

In: Computer Science

Develop the following code in such a manner that it shoulde be having extra 3 attempts(for...

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

Solutions

Expert Solution

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


Related Solutions

Develop the following code for quiz (i am getting some errors)in python in such a manner...
Develop the following code for quiz (i am getting some errors)in python 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...
4. [ 3 pts ]. Answer the following in a concise manner. (a) What is the...
4. [ 3 pts ]. Answer the following in a concise manner. (a) What is the difference between a loan, a cryptocurrency and a bond? (b) What is the difference between the money market and the capital market? (c) How can the stock option provision solve the principal-agent problem and reduce agency costs?
Borrowing money in a manner designed to avoid having to record the resulting obligation as a...
Borrowing money in a manner designed to avoid having to record the resulting obligation as a liability in the financial statements is referred to as: A) compensating balance financing B) off-balance sheet financing C) contingent financing D) deferred financing
I'm having trouble understanding the following code (a snippet of a code). What does it do?...
I'm having trouble understanding the following code (a snippet of a code). What does it do? The whole code is about comparing efficiencies of different algorithms. def partition(list,first,last): piv = list[first] lmark = first+1 rmark = last done = False while not done: while lmark <= rmark and list[lmark]<=piv: lmark=lmark+1 while list[rmark]>=piv and rmark>=lmark: rmark=rmark-1 if rmark<lmark: done = True else: temp = list[lmark] list[lmark]=list[rmark] list[rmark]=temp temp = list[first] list[first]=list[rmark] list[rmark]=temp return rmark
Develop a python program to create a quiz with limited time and attempts!!! Add comments and...
Develop a python program to create a quiz with limited time and attempts!!! Add comments and screenshot of running the program quiz could be of anything like , what's the sum of 2&2. There should be number of attempts(limited) suppose if the answer is wrong.
in a sustainable tourism what destinations do to implement or develop tourism in a sustainable manner
in a sustainable tourism what destinations do to implement or develop tourism in a sustainable manner
Linked Activity I: Develop Global Awareness, Thinking, and Code of Ethics Directions: Develop an Organizational Code...
Linked Activity I: Develop Global Awareness, Thinking, and Code of Ethics Directions: Develop an Organizational Code of Ethics for a company you either work for a fictional company or a known company you are interested in: Given the work-related attitudes and behaviors in the company you have selected : Identify at least eight (8) principles, values, attitudes, behaviors, policies, etc. your organization should establish to promote ethical behavior and decision-making among its employees. Explain how the Code of Ethics you...
Please fix this code I am having issues compiling it all together there is 3 codes...
Please fix this code I am having issues compiling it all together there is 3 codes here and it's giving me errors in my main method..... I feel like it might be something simple but I can't seem to find it. package assignement2; import java.util.ArrayList; import java.util.Scanner; public class reg1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter the number of items: "); int number = input.nextInt(); input.nextLine(); for (int i = 0; i <...
I need to develop a VHDL code for a FPGA basys 3, 4 digit 7 segment...
I need to develop a VHDL code for a FPGA basys 3, 4 digit 7 segment display. So when binary 0, 1 ,and 2 are inputted the display says bad. When binary 3,4,5,6, the display says good.
I need to develop a VHDL code for a FPGA basys 3, 4 digit 7 segment...
I need to develop a VHDL code for a FPGA basys 3, 4 digit 7 segment display. So when binary 0, 1 ,and 2 are inputted the display says bad. When binary 3,4,5,6, the display says good.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT