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"
5 Respostas
+ 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)
+ 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.
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
0
Thank you all for your help!
0
print=input (change)