Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Does anyone know why this code is not printing at the end?

+4 votes
asked Mar 12, 2020 by A coder in need
selected = 6
num1 = input("First number:")
if num1 == selected:
    print("Hi")

I entered 6 in the input

7 Answers

+4 votes
answered Mar 12, 2020 by Taha

Python 3 stores the input as 'string' type, So when you type 6, it is actually being stored as '6' of type string. And therefore 6 is not equal to '6'.
Use this instead:


num1 = int(input("First number:"))

0 votes
answered Mar 12, 2020 by jay (170 points)

you write     print("Hi")    rong

write             printf("Hi");     right

commented Mar 12, 2020 by Callum (240 points)
This Isn't C++, Idiot.
+1 vote
answered Mar 12, 2020 by anonymous
string "6" !=6

so u have to use int(input())
+1 vote
answered Mar 12, 2020 by Panguluri Navya (200 points)

input we give while run programm is string not intcool

0 votes
answered Mar 13, 2020 by anonymous

selected = 6
num1 =int( input("First number:"))
if num1 == selected:
    print("Hi")

 

0 votes
answered Mar 14, 2020 by Sarmad Khan (180 points)
This Is Python Question

selected = 6
num1 = int(input("First number:"))
if num1 == selected:
    print("Hi");

If We Input Funtion Types 6 The Print Function Show Us
0 votes
answered Mar 14, 2020 by rohith vanamala
num1=int(input("first number"))
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...