Write a program to check if string contain only Numbers
Question
Write a program to check if string contain only Numbers
Solution
Sure, here is a simple Python program that checks if a string contains only numbers:
def check_string(s):
if s.isdigit():
return True
else:
return False
s = "12345"
print(check_string(s))
s = "123abc"
print(check_string(s))
In this program, the isdigit() function is used to check if all the characters in the string are digits. If all characters are digits, the function returns True. Otherwise, it returns False. The program tests the function with two strings: "12345" and "123abc". The first string contains only digits, so the function returns True. The second string contains non-digit characters, so the function returns False.
Similar Questions
/*Write a program to check if a given number is COMPLETE NUMBER or NOTNote:A Number is said to be COMPLETE NUMBER if the individual digits of the number are all even if the individual digits of the number are not even then print NOT COMPLETE NUMBER
Write a program to check the given number is perfect or not ?
Single File Programming QuestionProblem StatementSathish wants to create a program to check whether its digits are in descending order. The program should output "Yes" if the digits are in descending order and "No" otherwise. He wants to get an integer input that has unique digits in it and determine whether the number meets this condition. Write a program to assist Sathish in completing this task using the goto statement.For example, In the number 4321, all the digits are in descending order.Input format :The input consists of an integer N, that represents the number to be checked.Output format :If the digits of N are in descending order, the output prints "Yes".Else, the output prints "No".Refer to the sample output for formatting specifications.Code constraints :In the given scenario, the test cases fall under the following constraints:1 ≤ N < 105Sample test cases :Input 1 :2589Output 1 :NoInput 2 :4321Output 2 :YesInput 3 :93578Output 3 :No
Check NumbersSend FeedbackPython program to check if a string has at least one letter and one numberGiven a string in Python. The task is to check whether the string has at least one letter(character) and one number. Return “True” if the given string fulfils the above condition else return “False” (without quotes).Input FormatStringOutput FormatBooleanInput 1welcome2ourcountry34Output 1TrueInput 2stringwithoutnumOutput 2False
Write a program to check the given number is perfect or not ?Constraints:1<n<1000Input FormatAn integer nOutput FormatA corresponding stringExample:Input 1:6Output 1:YesInput 2:3Output 2:No
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.