+ 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

16th Apr 2019, 6:47 AM
Pendar Alipour
Pendar Alipour - avatar
5 Answers
+ 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)
16th Apr 2019, 6:59 AM
Javier Felipe Toribio
Javier Felipe Toribio - avatar
+ 6
You're welcome
16th Apr 2019, 7:01 AM
Javier Felipe Toribio
Javier Felipe Toribio - avatar
+ 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😉🐍☕
23rd Apr 2019, 7:07 PM
Trigger
Trigger - avatar
+ 2
Tnx bro
16th Apr 2019, 7:00 AM
Pendar Alipour
Pendar Alipour - avatar
+ 1
Tnx javier. I like it.
23rd Apr 2019, 7:27 PM
Pendar Alipour
Pendar Alipour - avatar