+ 3

I want to ask a question :) tq

Why int first then input num = int(input()) if num < 100: print("number is lesser than 100") if num > 100: print("number is greater than 100") Tq for answering

6th Apr 2020, 11:09 AM
Muhd Daniel
Muhd Daniel - avatar
6 Antworten
+ 5
Muhd Daniel when you take an input by input() its actually taken in STRING format (words/sentence format) Even if someone types 12 which is an integer, it would be converted into a string like "12" so you can't calculate "12" + "24" coz the answer would be 1224 (both strings joined / concatenated) So you have to make sure we are only working with numbers so int(input()). float(input()) if a number can be with decimals too.
6th Apr 2020, 11:16 AM
maf
maf - avatar
+ 5
Can you please tell me why title is always placed after your name . Similarly each programing language have it's own syntex of writing. Got it ! 🤣😊
6th Apr 2020, 11:15 AM
Ayush Kumar
Ayush Kumar - avatar
+ 2
Because input() returns the input as string so if you want it to be integer you put int there so it converts string to int, in other words you are casting it.
6th Apr 2020, 11:13 AM
Mustafa K.
Mustafa K. - avatar
+ 1
Because if we use only input it gives you a string value that's why we use int for taking a integer Value.
7th Apr 2020, 9:22 AM
Ashish Singh
Ashish Singh - avatar
0
Tq for your help . Now i understand
7th Apr 2020, 5:32 AM
Muhd Daniel
Muhd Daniel - avatar
0
Because by default input function take input as a string and int function convert string into integer
7th Apr 2020, 1:28 PM
Rishi
Rishi - avatar