logo
down
shadow

Tried to add a value to a while condition, but it doesn't go back


Tried to add a value to a while condition, but it doesn't go back

By : Mauro
Date : November 19 2020, 07:01 PM
should help you out I'm making a guess game just for testing while loops, but I want an option so who plays can try again. , Just adjust your loop accordingly:
code :
b = 3
while b >= 0:
    if b == 0:
        print('You lost!')
        while True:
            again = input('Want to try again? [y/n] ').lower()
            if again != 'y' and again != 'n':
                pass
            else:
                break
        if again == 'n':
            break
        else:
            b += 3
    else:
        guess = int(input('Guess: '))
        if guess == 9:
            print('You win!')
            break
        else:
            b -= 1


Guess: 7
Guess: 6
Guess: 4
You lost!
Want to try again? [y/n] 3
Want to try again? [y/n] lol
Want to try again? [y/n] y
Guess: 3
Guess: 2
Guess: 1
You lost!
Want to try again? [y/n] n


Share : facebook icon twitter icon
Why doesnt this go back to white?

Why doesnt this go back to white?


By : guilherme contesini
Date : March 29 2020, 07:55 AM
wish helps you Apart from the obvious error with the wrong use of assignment operator, you can write it better.
As you are overriding the className, there is no need to use removeAttribute so
code :
function ChangeClass(SelectedDiv) {
  var el = document.getElementById(SelectedDiv);
  el.className = el.className == "Unselected" ? 'Selected' : 'Unselected';
}
.Unselected {
  background-color: white;
  width: 20%;
  height: 20px;
  border: thin solid black;
  border-radius: 4px;
  float: left;
  margin-right: 6px;
  vertical-align: middle;
  line-height: 20px;
}
.Selected {
  background-color: green;
  width: 20%;
  height: 20px;
  border: thin solid black;
  border-radius: 4px;
  float: left;
  margin-right: 6px;
  vertical-align: middle;
  line-height: 20px;
}
<div class='Unselected' id='Div1' onclick="ChangeClass('Div1');">Div1<div>
function ChangeClass(SelectedDiv) {
  var el = document.getElementById(SelectedDiv);
  el.classList.toggle('Unselected');
  el.classList.toggle('Selected');
}
.Unselected {
  background-color: white;
  width: 20%;
  height: 20px;
  border: thin solid black;
  border-radius: 4px;
  float: left;
  margin-right: 6px;
  vertical-align: middle;
  line-height: 20px;
}
.Selected {
  background-color: green;
  width: 20%;
  height: 20px;
  border: thin solid black;
  border-radius: 4px;
  float: left;
  margin-right: 6px;
  vertical-align: middle;
  line-height: 20px;
}
<div class='Unselected' id='Div1' onclick="ChangeClass('Div1');">Div1<div>
IF Condition doesnt work

IF Condition doesnt work


By : Lambosaur
Date : March 29 2020, 07:55 AM
Hope that helps Am trying to make an IF condition but it's not working well. I want when the EditText is null, the user doesn't go to the next Activity. , Use this :
code :
one_next_diaspora_bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                final String Name = name_diaspora_edt.getText().toString().trim();
                if(Name.matches("")){


                    Toast.makeText(getApplicationContext(),"Make sure that you have filled your name please !!!",Toast.LENGTH_LONG).show();


                }

                else{



                    Intent i = new Intent(Diaspora.this,DiasporaTwo.class);
                    i.putExtra("Name",Name);
                    i.putExtra("Age",Age);
                    i.putExtra("Gender",Gender);
                    i.putExtra("MaritalStatus",MaritalStatus);
                    startActivity(i);
                }
            }
        });
}
vue js transition doesnt wok with v-if condition

vue js transition doesnt wok with v-if condition


By : Jannis Froese
Date : March 29 2020, 07:55 AM
I wish did fix the issue. Problem : v-if actually remove element if found false. and transition works on existing element. and which have display:none
Solution : Vue uses special transition attribute
code :
new Vue({
  el: '#demo',
  data: {
    transition: true
  }
})
.fade-enter-active, .fade-leave-active {
  transition: opacity .5s;
}
.fade-enter, .fade-leave-to /* .fade-leave-active below version 2.1.8 */ {
  opacity: 0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.16/vue.js"></script>

<div id="demo">
  <transition name="fade">
    <p v-if="transition">This will work</p>
  </transition>
  <button v-on:click="transition = !transition">
    Toggle
  </button>
  
</div>
new Vue({
  el:'#app',
  data:{
    name:'niklesh',
    transition:false
  },
  methods:{
    addTrans:function(){
      this.transition = !this.transition;
    }
  }
});
.article-list-enter-active{
  transition: all 2s;
}
.article-list-enter{
  opacity: 0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.16/vue.js"></script>
<div id="app">
<div v-if="transition" class="article-list-enter-active " v-bind:class="!transition ? 'article-list-enter':''">
  Transtion  will not work
</div>

<div v-show="transition" class="article-list-enter-active " v-bind:class="!transition ? 'article-list-enter':''">
  Transtion  will not work
</div>


<div class="article-list-enter-active " v-bind:class="!transition ? 'article-list-enter':''">
  Transtion  will work
</div>

<button type="button" @click="addTrans">Click to see transition</button>

</div>
Why does my FirstFactorial program keep looping back to while condition even after the condition is not met

Why does my FirstFactorial program keep looping back to while condition even after the condition is not met


By : Sahm Zheii
Date : March 29 2020, 07:55 AM
like below fixes the issue Here's the code snippet, this when run with number 4 outputs 2424242448484848288288288288576576576576. Not sure as to why would the execution would jump back to while loop after exiting the function code. Any help will be appreciated. Thank you in advance. , Within the function
code :
void
FirstFactorial(int num)
{
  // code goes here
  while(num > 0)
    {
      result = result * num;
      num--;
      FirstFactorial(num);
    }
  printf("%d", result);
}
#include <stdio.h>

unsigned long long int factorial( unsigned long long int n )
{
    return n < 2 ? 1 : n * factorial( n - 1 );
}

int main(void) 
{
    printf( "%llu! = %llu\n", 4llu, factorial( 4 ) );
    printf( "%llu! = %llu\n", 20llu, factorial( 20 ) );

    return 0;
}
4! = 24
20! = 2432902008176640000
Try Catch doesnt try the second condition

Try Catch doesnt try the second condition


By : jec13
Date : March 29 2020, 07:55 AM
Hope that helps You are not getting a NullReferenceException, that's why the catch does not "catch".
You will receive null reference exception if you are using a property of that instance and it is null for example:
Related Posts Related Posts :
  • Removing non-breaking spaces from strings using Python
  • Is there a way to backup everything in an app-engine blobstore?
  • Process a set of files from a source directory to a destination directory in Python
  • How to know if optparse option was passed in the command line or as a default
  • Rewriting a for loop in pure NumPy to decrease execution time
  • Comparing a time delta in python
  • Find next lower item in a sorted list
  • MySQLdb not INSERTING, _mysql does fine
  • Scipy Negative Distance? What?
  • What are the common patterns in web programming?
  • Percent signs in windows path
  • How to add a random number to a subsection of a numpy array?
  • How to generate all the values of an iterable besides the last few?
  • Searching by both class and range in XPath
  • Python code execution in Perl interpreter
  • Best Way to Include Variable in Python3
  • Serialize the @property methods in a Python class
  • What is the most platform- and Python-version-independent way to make a fast loop for use in Python?
  • Good way to edit the previous defined class in ipython
  • Bounced email on Google App Engine
  • Search jpeg files using python
  • Dynamically create class attributes
  • python unichr problem
  • Python beginner, strange output problem
  • Python: Finding a value in 1 list and finding that corresponding index in another list
  • can't install mysqlclient on mac os x mojave
  • Error indicates flattened dimensions when loading pre-trained network
  • how to replace underlines with words?
  • Adding through iteration
  • Use OpenCV on deployed Flask app (Heroku)
  • How to skip interstitial in a django view if a user hits the back button?
  • Any Naive Bayesian Classifier in python?
  • Python 2.5.2: remove what found between two lines that contain two concrete strings
  • Python 2.5.2 script that add "The function starts here" to all the functions of the files of a directory
  • HttpResponseRedirect question
  • Python socket error on UDP data receive. (10054)
  • Encoding issues with cloud ml
  • numpy.where - Weird behaviour: new elements spawning from nowhere?
  • I can't move my player in pygame, can you figure why?
  • Weird error I receive from Tkinter in Python
  • Using a Zapier Custom Request Webhook with JSON Web Tokens
  • Keras: Use categorical_crossentropy without one-hot encoded array of targets
  • Does python's httplib.HTTPConnection block?
  • Do alternate python implementation version numbers imply that they provide the same syntax?
  • Searching for specific HTML string using Python
  • python sax error "junk after document element"
  • MySql: How to know if an entry is compressed or not
  • Return a list of imported Python modules used in a script?
  • Returning a list in this recursive coi function in python
  • Python2.6 Decimal to Octal
  • Appengine Apps Vs Google bot web crawler
  • Changing models in django results in broken database?
  • Global variable functions
  • Using lambda inside a function
  • How to open a file, replace some strings, and save updates to the same file?
  • How to move the beginning of an input to the and?
  • If else fill variable if empty list
  • Pandas: Find and print all floats in column
  • sqlite3.OperationalError: database is locked - non-threaded application
  • How to implement mib module in net-snmp with python?
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk