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 having trouble with my assignment and getting compile errors on the following code. The...
I am having trouble with my assignment and getting compile errors on the following code. The instructions are in the initial comments. /* Chapter 5, Exercise 2 -Write a class "Plumbers" that handles emergency plumbing calls. -The company handles natural floods and burst pipes. -If the customer selects a flood, the program must prompt the user to determine the amount of damage for pricing. -Flood charging is based on the numbers of damaged rooms. 1 room costs $300.00, 2 rooms...
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;...
In the following code down below I am not getting my MatrixElementMult right. Could someone take...
In the following code down below I am not getting my MatrixElementMult right. Could someone take a look at it and help fix it? Also, when I print out the matrices I don't want the decimals. I know it's a format thing but I'm new to C and not getting it. Thanks! #include <stdlib.h> #include <stdio.h> #include <math.h> #define N 8 typedef struct _Matrix { double element[N][N]; } Matrix; void PrintMatrix(Matrix a){ int i,j; for(i=0;i<N;i++){ for(j=0;j<N;j++){ printf(" %.1f ",a.element[i][j]); }...
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):      ...
this is my code in python I am trying to open a file and then print...
this is my code in python I am trying to open a file and then print the contents on my console but when i run it nothing prints in the console def file_to_dictionary(rosterFile): myDictionary={}    with open(rosterFile,'r') as f: for line in f: myDictionary.append(line.strip()) print(myDictionary)             return myDictionary    file_to_dictionary((f"../data/Roster.txt"))      
c++ I am getting errors that say "expected a declaration". can you explain what it means...
c++ I am getting errors that say "expected a declaration". can you explain what it means by this and how I need to fix it?   #include <iostream> using namespace std; //functions void setToZero(int board[8][8]); void displayBoard(int oboard[8][8]); void movingFunction(); int main() {    // chess board 8x8    int board[8][8];    // all of the possible moves of the knight in 2 arrays    int colMove[8] = { 2, 1, -1, -2, -2, -1, 1, 2 };    int rowMove[8]...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT