Why can't i get a string n times | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why can't i get a string n times

I wanted to get math printed n times print("how many math do you want") n=input("enter n") print("math"*n)

10th Oct 2017, 1:20 PM
Manasa Devi Chakka
Manasa Devi Chakka - avatar
7 Answers
+ 3
The second line should be: n=int(input("Enter n")) Hope this helps! :)
10th Oct 2017, 1:32 PM
Shinjini Ghosh
0
actually u are not taking int input else your code is correct print("how many math do you want") n=int(input("enter n")) print("math"*n)
10th Oct 2017, 1:40 PM
Talha Farooq
Talha Farooq - avatar
0
what if I give the input as an integer for n but hasn't declared it as integer
10th Oct 2017, 1:57 PM
Manasa Devi Chakka
Manasa Devi Chakka - avatar
0
it will by default take as string.
10th Oct 2017, 1:58 PM
Talha Farooq
Talha Farooq - avatar
0
but the code gave me output as below >>>n= input("enter n") enter n5 >>>print(n) 5 >>>print('n') n
10th Oct 2017, 2:01 PM
Manasa Devi Chakka
Manasa Devi Chakka - avatar
0
n=input("no") print(n) z=n*2 print(z) check this if you put 5 input it should result 10 but in python it results 55 as str is multiple by 2 instead when u use int it will take as an int input.
10th Oct 2017, 2:17 PM
Talha Farooq
Talha Farooq - avatar
0
ok, I got it now. Thanks for your clarification.
10th Oct 2017, 2:24 PM
Manasa Devi Chakka
Manasa Devi Chakka - avatar