logo
down
shadow

How to end program after right answer?


How to end program after right answer?

By : Srinivas Kagitapu
Date : October 17 2020, 06:10 PM
Hope this helps First and forement, the bug
You have a bug in your code. If you win on the first round, it will detect this successfully. On the second and third round, any victory will be purely coincidence.
code :
window.prompt(...)
answer = window.prompt(...)
if (win) {
   // say you won
} else {
   // say you lost
}



if (win) {
   // say you won
} else {
   // say you lost
}



if (win) {
   // say you won
} else {
   // say you lost
}
if (win) {
   // say you won
} else {
   // say you lost
   if (win) {
      // say you won
   } else {
      // say you lost
      if (win) {
         // say you won
      } else {
         // say you lost
      }
   }
}
var random = Math.floor(Math.random() * 10);
var random1 = Math.floor(Math.random() * 10);
var random2 = Math.floor(Math.random() * 10);

var answer = window.prompt("Make a guess from 1 to 10, you have 3 chances."); 
if (answer == random) {
    alert("HORAAYYYY YOU GOT IT RIGHT!!!"); 
}
else {
    alert("Sorry, the correct answer was " + random);
    answer = window.prompt("Make a guess from 1 to 10, you have 2 chances left.");
    if (answer == random1) {
        alert("HORAAYYYY YOU GOT IT RIGHT!!!"); 
    }
    else {
        alert("Sorry, the correct answer was " + random1);
        answer = window.prompt("Make a guess from 1 to 10, you have 1 chance left.");
        if (answer == random2) {
            alert("HORAAYYYY YOU GOT IT RIGHT!!!"); 
        }
        else {
            alert("Sorry, the correct answer was " + random2);
            alert("You've lost");
        }
    }
}
var youHaveWon = false;

while( ! youHaveWon ) {
    var random = Math.floor(Math.random() * 10);
    var answer = window.prompt("Make a guess from 1 to 10");
    if (answer == random) {
        alert("HORAAYYYY YOU GOT IT RIGHT!!!"); 
        youHaveWon = true;
    }
    else {
        alert("Sorry, the correct answer was " + random);
    }
}
var youHaveWon = false;
var guessesRemaining = 3;

while( ! youHaveWon && guessesRemaining > 0 ) {
    var random = Math.floor(Math.random() * 10);
    var answer = window.prompt("Make a guess from 1 to 10... you have " + guessesRemaining + " more guesses");
    if (answer == random) {
        alert("HORAAYYYY YOU GOT IT RIGHT!!!"); 
        youHaveWon = true;
    }
    else {
        alert("Sorry, the correct answer was " + random);
    }
    guessesRemaining = guessesRemaining - 1;
}

if ( ! youHaveWon ) {
    alert("You lost");
}


Share : facebook icon twitter icon
Python 3.x - If quitting program, at the y/n conditional how do I make the no answer go back to the start of program?

Python 3.x - If quitting program, at the y/n conditional how do I make the no answer go back to the start of program?


By : Gelgameks
Date : March 29 2020, 07:55 AM
hop of those help? You will definitely need a loop of some kind. This could work for you:
code :
while True:
    # do some stuff

    if (want_to_go_to_start_early):
        continue # Go back to the start of the loop

    if (want_to_exit_loop):
        break    # Exit the loop

    # do other stuff in the loop

    # at the end of the loop it goes back to the top

# stuff outside the loop (only gets reached after the 'break')
Searching for an answer why the answer in the book is not equal to the answer I receive from my program

Searching for an answer why the answer in the book is not equal to the answer I receive from my program


By : Olivier Lasserre
Date : March 29 2020, 07:55 AM
I wish this help you The answer in the book is wrong. If you do it by hand, your program's results are the correct ones: 3.5^2*sqrt(3)/4 = 5.3.
I intend to write a quiz program that adds up points when the answer is correct and deducts point when a wrong answer is

I intend to write a quiz program that adds up points when the answer is correct and deducts point when a wrong answer is


By : sandeep
Date : March 29 2020, 07:55 AM
I hope this helps you . The problem in your code is that you're using the or operator wrongly in the if condition.
In general, if you want to check the variable a against values B and C, you would need to do:
code :
if a == B or a == C:
if a == B or C
if a in [B, C, D, ...]:
if answer1 == "d" or "D" or "Nnamdi" or "Nnamdi Azikwe" and "Azikwe":
if answer1 in ["d", "D", "Nnamdi", "Nnamdi Azikwe", "Azikwe"]:
questions = [
    {
        "question": "What is the name of the first president of Nigeria?",
        "options": ["Amadu Bello", "Shehu Shagari", "Olusegun Obasanjo", "Nnamdi Azikwe"],
        "answers": ["d", "nnamdi", "nnamdi azikwe", "azikwe"]
    },
# add more questions here in the same format as above
]

name = str(input("What is your name?: "))
score = 0

for q_number, q in enumerate(questions):
    question_text = '({}) {}\n'.format(q_number + 1, q["question"])
    options_text = '\n'.join("({}) {}".format(chr(i + 65), qsn) for i, qsn in enumerate(q["options"])) + "\n"
    display_text = question_text + options_text

    # answer is converted to lower case to make comparison with options easier
    answer = str(input(display_text)).lower()

    if answer in q["answers"]:
        score += 5
        print ("Well done", name, "you've scored", score, "points")
    else:
        score -= 5
        print("ouch!!!", name, "you missed that, you've scored, ", score, "points")
Answer set of a program - why is the empty set not an answer set?

Answer set of a program - why is the empty set not an answer set?


By : Tudor Oprea
Date : March 29 2020, 07:55 AM
To fix this issue Empty set is an answer set of a :- b.. Try running your example online: https://potassco.org/clingo/run/
code :
clingo version 5.3.0
Reading from stdin
-:1:6-7: info: atom does not occur in any rule head:
  b

Solving...
Answer: 1

SATISFIABLE

Models       : 1
Program giving wrong answer when written but gives right answer when copied

Program giving wrong answer when written but gives right answer when copied


By : Bency
Date : March 29 2020, 07:55 AM
To fix the issue you can do I was doing selection sort. The program that I wrote was generating wrong result but when I copied it from a site. The codes are exactly the same except the one copied from the website has more number of spaces. I am providing both the codes. Please help The code written by me: , They are not the same - in one you have:
Related Posts Related Posts :
  • Set field in mongoose document to array length
  • disable Double tap zoom/resize on safari IOS12***
  • how to add a wait in time in a for ..of?
  • Time Spent by user on a web page + Iframe
  • animate.css is not working in Chrome latest version (Version above 73)
  • Row selection and pagination - Vue
  • How can I use function chaining with dates in JavaScript?
  • What is the difference between "delete" and "Reflect.deleteProperty()"
  • How to get attributes of individual elements in jquery array
  • Why do I get different results with "=" vs. "===" in javascript with Conditional (Ternary) Operators
  • I am trying to hold value of document.getElementById("image").src=UserInput +".gif"
  • Array being pushed into another array isn't displaying
  • Is there a React.js NPM module or any other solution for image/object mutli-selection?
  • 80% Javascript Solution for Flags in Codility
  • I want to display background while scrolling down
  • RegEx for matching text between two tags
  • Does having a lot of inner 'helper' functions inside a functional stateless react component will result in worse perform
  • How to submit a form through a button outside the form?
  • ESLint: Use callback in setState when referencing the previous state
  • How to parse state from one component to another in my example?
  • Visible Html select option showing under hidden items
  • Create SVG circle using path with 6 segments
  • Getting error while reading from a text file
  • Read a value from JSON Array without entity
  • Checkbox check or uncheck value null
  • Displaying multiple slider values to users
  • Am doing the destructing right?
  • VueJS data-bind object styling not working
  • Combine array and object destructuring
  • Execution skips promise statements
  • sort an array of objects leaving first field
  • how to highlight table cells in a certain way when hover over
  • Problems when using Chosen Selectors in external helper functions
  • Need to merge two objects together that each have an array to the matching IDs
  • How to get previous 6 months date from current date in javascript
  • how to get object value only without mentioning key from array list using ngFor in angular 7
  • Plugging into on_page_change events in testcafe
  • WithStore: Cannot read property 'state' of undefined (pure-react-carousel)
  • fullcalendar event info in modal popup
  • How do i reduce time complexity of this code
  • Deep comparing object props in React not working as expected
  • JavaScript method to remove case insensitive duplicates from string/Numbers
  • When to use parentheses after function name call (es6)
  • Convert list of Objects when the levels are given in an array
  • template variable always undefined ngOnChanges
  • RegEx for matching the first word
  • Render different au-target-id in aurelia repeat
  • Why does the function start before the button is pressed?
  • where can I vote for changes to javascript?
  • Change the digit format pagination in the slider
  • Hover/focus state activated initially on page load
  • Why do my normal sync codelines, works like async?
  • How to prevent or disable Bootstrap 4 popover auto positioning behavior (Self adjusting behavior)
  • What is the meaning of ({})?
  • How do I make a link to a property if the property is yet to be declared? (In a Class)
  • Getting Promise as return value inside FlatList React-native
  • Why can't you access JSON directly from the response in Fetch API?
  • How to grab value out of this nested array
  • function is not returning any value
  • "Cannot read property 'map' of undefined (React.js)"
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk