#### Category : if-statement

Could someone help me on making a range between two decimal numbers say 18.5 to 24.9? So basically what I wanted to do is this If BMI in range(18.5, 24.9) print("good you are healthy") Yet it would not allow me to do this. When I tried to do this it said expected int got float ..

This is my code: import random letters = [‘a’,’g’,’s’,’s’,’c’,’v’,’e’,’g’,’d’,’g’] random_letter = random.choice(letters) guesses_left = 5 while guesses_left > 0: guess = input("Your guess: ") if guess == random_letter: print ("You win!") break guesses_left -= 1 else: print ("You lose.") My question: Why am I able to type other types than strings? For example, if I ..

I have tried to remove an element by using if condition in a list, if the list is like this list1 = [‘a’,’1′,’c’,’2′,’d’,’3′] for i in list1: if i == ‘a’ : list1.pop(list1.index(i) – 1) list1.remove(i) print(list1) Output : [‘c’, ‘2’, ‘d’, ‘3’] It removes all ‘a’ in the list but when ‘a’ is near ..

For some dumb reason, I can’t get my if..elif to print in python 3 but it somehow works in python 2. I’m not sure what I missed. This is my if, elif def encdec(userinput, machine, plaintext): if userinput == 1: print("———————————–") print("Encoded:") enc = machine.encrypt(plaintext) print(enc) elif userinput == 2: print("———————————–") print("Decoded:") dec = machine.decrypt(plaintext) ..

So I made a game with a life system in Python, that everytime you get a wrong answer you loose one life, and have the opportunity to try again. It worked properly with questions wiht a single answer, but then I had the neccessity to create questions with more than one answer. Now it keeps ..

I am looking for a way to compute the sum of integers between 1 and 20 that can be divided by 2, 3 or 5. I created an array with the integers from 1 to 20. Y= np.arange(1, 21, 1) However I am not sure how to check if the integers can be divided by ..

The title is a bit confusing, so I’ll give an example. Say I have a set of 4 conditions, [A,B,C,D], where each condition can either be true or false. For example, condition A can either say A[i,j+1] == 0 or A[i,j+1] != 0 I want an if statement that essentially says the following: if (in ..