0

Why the output (is 555 when ip is 5) in playground

s = input("Enter amount please: ") print(s) print ('new payment will be: ') y=s+(s*2) print (y)

6th Jun 2020, 2:20 PM
guruprakash s
guruprakash s - avatar
6 ответов
+ 7
You are basically adding string to string So if someone enters 450 It's "450"+("450"*2) which is 450450450 Remember input returns string you need to convert the input to int explicitly int(input())
6th Jun 2020, 2:24 PM
Abhay
Abhay - avatar
+ 3
The input is a string '5' and not a number. s = int(input()) will make it a number.
6th Jun 2020, 2:26 PM
Paul
Paul - avatar
+ 2
What is the output?
6th Jun 2020, 2:22 PM
Abhay
Abhay - avatar
+ 1
Ok.. got it.. tysm
6th Jun 2020, 2:24 PM
guruprakash s
guruprakash s - avatar
0
How to return a string value?
6th Jun 2020, 2:25 PM
guruprakash s
guruprakash s - avatar
0
Oh ok.. i was trying with int x = input () which was error Ty..
6th Jun 2020, 2:30 PM
guruprakash s
guruprakash s - avatar