Question

In: Computer Science

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 out of 3

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

Solutions

Expert Solution

Code:

score=0

total_attempts=3

def question1(attempts,score):

  print('What colors are apples?\na) Red/Green\nb) Orange\n')

  answer1=input('enter answer: ')

  if(answer1=='a'):

    score=score+1

    return attempts,score

  else:

    attempts-=1

  if attempts<=0:

    print('No More Attempts')

    return attempts,score

  else:

    print('try again')

    return question1(attempts,score)

def question2 (attempts,score):

  print('What colors are bananas?\na) Red/Green\nb) Yellow\n')

  answer1=input('enter answer: ')

  if(answer1=='b'):

    score=score+1

    return attempts,score

  else:

    attempts-=1

  if attempts<=0:

    print('No More Attempts')

    return attempts,score

  else:

    print('try again')

    return question2(attempts,score)

def question3 (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

    return attempts,score

  else:

    attempts-=1

  if attempts<=0:

    print('No More Attempts')

    return attempts,score

  else:

    print('try again')

    return question3(attempts,score)

def questions():

  kk=question1(total_attempts,score)

  if kk[0]>0:

    hh=question2(kk[0],kk[1])

    if hh[0]>0:

      q=question3(hh[0],hh[1])

      print('score = ',q[1])

    else:

      print('score = ',hh[1])

  else:

    print('score = ',kk[1])      

Please refer to the screenshot of the code to understand the indentation of the code:

Output (which can be done by calling questions() ):

1.

2.

3.

For any doubts or questions comment below.


Related Solutions

I am currently having trouble understanding/finding the errors in this python code. I was told that...
I am currently having trouble understanding/finding the errors in this python code. I was told that there are 5 errors to fix. Code: #!/usr/bin/env python3 choice = "y" while choice == "y": # get monthly investment monthly_investment = float(input(f"Enter monthly investment (0-1000):\t")) if not(monthly_investment > 0 and monthly_investment <= 100): print(f"Entry must be greater than 0 and less than or equal to 1000. " "Please start over.")) #Error 1 extra ")" continue # get yearly interest rate yearly_interest_rate = float(input(f"Enter...
I am getting 7 errors can someone fix and explain what I did wrong. My code...
I am getting 7 errors can someone fix and explain what I did wrong. My code is at the bottom. Welcome to the DeVry Bank Automated Teller Machine Check balance Make withdrawal Make deposit View account information View statement View bank information Exit          The result of choosing #1 will be the following:           Current balance is: $2439.45     The result of choosing #2 will be the following:           How much would you like to withdraw? $200.50      The...
This is in Python I am getting an error when I run this program, also I...
This is in Python I am getting an error when I run this program, also I cannot get any output. Please help! #Input Section def main(): name=input("Please enter the customer's name:") age=int(input("Enter age of the customer: ")) number_of_traffic_violations=int(input("Enter the number of traffic violations: ")) if age <=15 and age >= 105: print('Invalid Entry') if number_of_traffic_violations <0: print('Invalid Entry') #Poccessing Section def Insurance(): if age < 25 and number_of_tickets >= 4 and riskCode == 1: insurancePrice = 480 elif age >=...
I am creating SAS code, but am receiving an errors " ERROR: Value is out of...
I am creating SAS code, but am receiving an errors " ERROR: Value is out of range or inappropriate. ERROR: No body file. HTML5(WEB) output will not be created." This is the code: option ls=65 ps=65; data one; input IQ; cards; 145 139 122 ; title 'Normal Quantile - Quantile Plot for IQ'; ods graphics on; proc univariate data=one; qqplot IQ / normal (mu=est sigma=est); run;
Can someone please tell me why I am getting errors. I declared the map and it's...
Can someone please tell me why I am getting errors. I declared the map and it's values like instructed but it's telling me I'm wrong. #include <iostream> #include <stdio.h> #include <time.h> #include <chrono> #include <string> #include <cctype> #include <set> #include <map> #include "d_state.h" using namespace std; int main() { string name; map<string,string> s; map<string,string>::iterator it; s[“Maryland”] = "Salisbury"; s[“Arizona”] = "Phoenix"; s[“Florida”] = "Orlando"; s[“Califonia”] = "Sacramento"; s[“Virginia”] = "Richmond"; cout << "Enter a state:" << endl; cin >> name;...
This is my code for python. I am trying to do the fourth command in the...
This is my code for python. I am trying to do the fourth command in the menu which is to add an employee to directory with a new phone number. but I keep getting error saying , "TypeError: unsupported operand type(s) for +: 'dict' and 'dict". Below is my code. What am I doing wrong? from Lab_6.Employee import * def file_to_directory(File): myDirectory={}       with open(File,'r') as f: data=f.read().split('\n')    x=(len(data)) myDirectory = {} for line in range(0,199):      ...
I'm getting an error with my code on my EvenDemo class. I am supposed to have...
I'm getting an error with my code on my EvenDemo class. I am supposed to have two classes, Event and Event Demo. Below is my code.  What is a better way for me to write this? //******************************************************** // Event Class code //******************************************************** package java1; import java.util.Scanner; public class Event {    public final static double lowerPricePerGuest = 32.00;    public final static double higherPricePerGuest = 35.00;    public final static int cutOffValue = 50;    public boolean largeEvent;    private String...
I am struggling with c++ and I could use some guidance getting through this project. Below...
I am struggling with c++ and I could use some guidance getting through this project. Below are my directions. The objective of this project is to be able to incorporate structures in a program. The program will have the user enter the information for two movies (details below) and then display a list of recommended movies that have 4 or more stars. 1. You will need to create a structure named MovieInfo that contains the following information about a movie:...
Using Python, I am trying to integrate 'iloc' into the line of code below? This line...
Using Python, I am trying to integrate 'iloc' into the line of code below? This line is replacing all the '1' values across my .csv file and is throwing off my data aggregation. How would I implement 'iloc' so that this line of code only changes the '1's integers in my 'RIC' column? patient_data_df= patient_data_df.replace(to_replace=[1], value ="Stroke") Thank you:)
I am getting confused on finding the ethical challanges to this question. I am understanding but...
I am getting confused on finding the ethical challanges to this question. I am understanding but second guessing my answers when it come to the elements and the Ethical Code Standards. 1. Identify an ethical challenge for each element (a-d) of Dr Lux advertising plan. Which General Principles and Ethical Code Standards best help understand why these elements may create ethical problems? Explain why. Case 5. Web-Based Advertising. Dr. Lux, an applied developmental psycholgoist, has created his own community consulation...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT