Character in input | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Character in input

""" write a code that decides if the input can be divided by 3 and/or 5 without remainder""" x = int(input()) def threefive(): while x % 3 == 0 or x % 5 == 0: return True if x % 3 !=0 or x % 5 != 0: return False else: print("Invalid input!") print(threefive()) I'd like to know what should I write to the else: to output the "Invalud input!" when the input has character(s) in it? Thanks in advance!

1st Dec 2021, 12:48 PM
Kajtár László
Kajtár László - avatar
2 Answers
+ 3
Written like that it'll cause an error, so you'd just need a try and except block. If you don't want error you can take your input as string, check it with .isdigit() and then convert to an integer
1st Dec 2021, 12:56 PM
Slick
Slick - avatar
0
Thank you!
1st Dec 2021, 4:09 PM
Kajtár László
Kajtár László - avatar