How i code in python by using [if statement] | SoloLearn: Learn to code for FREE!

0

How i code in python by using [if statement]

I donot get code by using [if statement]

5/5/2021 4:53:58 PM

Devender singh

16 Answers

New Answer

+1

Devender singh Try do it : n = int(input(" ")) if n == 10: print ("2") else: print ("1") The motive of is printing the else is why we dont putted the int,and he confused thinked of it was a sting Happy coding πŸ€—πŸ‡§πŸ‡·

+5

Devender singh in your code-- example : n = input(" ") if n == 10: print ("hi") else: print ("Hello") the if condition will be true and executed when and only when you will put n=10, except n=10 no value of n will make the if condition true. So for different value of n else condition will be executed and you will get" Hello" as an output. Hope things will be clear nowπŸ‘πŸ‘

+3

thisIsPython = True if thisIsPython: print("This is Python")

+2

1. Your indentation is incorrect. 2. The input statement reads a string not a number. N = int(input()) if N > 10: print ("greater than 10") else: print ("False") See how the int() function converts the input to an integer value. It will throw an error if the input cannot be converted. There is no need to place a string inside the input() function unless you want a prompt on screen (doesn't work too well in the code playground) N = int(input("Enter an Integer: ")) If you do not convert the input to an integer the line if N > 10: will fail because N contains a string that you are comparing with an integer. If you do not want to perform the conversion at the time of input use N = input() if int(N) > 10: This will convert N to an integer before the comparison. I can see from your profile that you are taking the Python for Beginners course. If you have not done so already take a look at the Section "Variables" and the lessons "Taking User Input" and "Working with Input". If you have already completed these lessons you may wish to revisit them.

+1

N = input (" ") if N == 1: print ("Its equal 1") else: print ("2,3,4,5,6...")

+1

πŸ‡¨β€ŠπŸ‡¦β€ŠπŸ‡Ήβ€Š 🦊 i enter your code n = input(" ") if n == 10: print ("hi") else: print ("Hello") When i enter input less than 10 or greater than so it show hello output But when i enter 10 then it also show hello but why

+1

I will share my code https://code.sololearn.com/cJD54sC82lPJ/?ref=app

+1

When n = 10 output show hi but it not show it show hello

+1

Just make sure you put a collon (:) at the end of the statement also keep an eye on indentation.

0

Please explain in detail

0

My code want idented block i do not know what mistake i do in code please give me correct of it https://code.sololearn.com/cr4jnePssMDA/?ref=app

0

Devender singh You have to tab the print in if the else have to be togheter with if example : n = input(" ") if n == 10: print ("hi") else: print ("Hello")

0

Devender singh show your code and if you dont understad the if statemente see him again in the lessons

0

Devender singh the motive of the output is hello is : the if is saying N is EQUAL of 10,if he be greater or less,will print the else's print

0

πŸ‘

0

🦊 Cα΄€α΄› α΄„α΄œα΄›α΄‡β€Š See my under code is it right it give only one output: https://code.sololearn.com/cUIexbYdj3yi/?ref=app