0

print("Enter any number:") n = input () n=n*5 print(n) In the above program, if I try to multiply the given integer with 5 , to get output as "5n". Instead it prints as "nnnnn". Could anyone help me to solve it ?

if n = 15 I need get output as "75" instead of "1515151515"

13th Sep 2016, 9:15 AM
RAKESH
5 Respuestas
+ 5
n = input("Write a number") n = int(n)*5 print(n) # when you get a value with input(), this value, even if you type a number, is a string, ie: "5" (string) not 5 (number) # so, to transform the "5" in 5, you use the function int(5)
13th Sep 2016, 9:49 AM
Giovanni Gatto
Giovanni Gatto - avatar
+ 1
The type of n after the input is string. So, n*5 repeats the string five times. You must convert string to int, as Giovanni does in line 2.
13th Sep 2016, 10:14 AM
carberlaf
0
yes carberlaf, and that is why the input () function returns a string that must be converted in an integer, otherwise python will do that funny thing of repeating a string for 5 times
13th Sep 2016, 1:05 PM
Giovanni Gatto
Giovanni Gatto - avatar
0
Thank you all for your help!
13th Sep 2016, 3:25 PM
RAKESH
0
print=input (change)
14th Sep 2016, 1:43 PM
अनुराग
अनुराग - avatar