+ 3
Checking type
Hi. I want to be sure the entery for "repeat" is integer. And i want use a condition like IF or ... to make a warning when the "type of repeat" is not ineger. (Sorry for my bad English 😶) https://code.sololearn.com/c8UNLJfoCZXl/?ref=app
5 Respostas
+ 8
Do this:
if(repeat.isdigit()):
print(mystr * int(repeat))
else:
print("It's not a number !!!")
Don't forget to convert the string with numbers to a number with int(str)
+ 6
You're welcome
+ 3
As an alternative to Javier Felipe Toribio's solution, you can use a try-except block like:
try:
print(mystr * int(repeat))
except:
print("Is not a number")
Its much easier and is does what it was designed to do😉🐍☕
+ 2
Tnx bro
+ 1
Tnx javier. I like it.