+ 1
homework help
can you guys please help with my homework the prompt is to print “your input confains only digits” if the input is only numbees and print”your input contains more than just digits” if the input contains any other characters beside numbers
8 ответов
+ 10
Think about the string method isdigit(). It returns True if all characters in a string are digits and False if not.
+ 8
We are here to help you but not on homework, on your problem. So first try to do by yourself.
+ 7
Okay we're not a homework help community but I would like you to work on these hints:
- You should scan through every character.
- For your code to return the 2nd output, any number of non-digits can be present. Even one.
+ 6
OK here's a one-liner using an f-string and isdigit()
print(f"Your input contains {'only' if input().isdigit() else 'more than just'} digits.")
https://code.sololearn.com/c7d8G0EnE73O
+ 2
You can use function ord() for single characters.
if the returned value is between 33 and 42, the character is a digit.
48 <= ord("0") <= 57 ---> True
48 <= ord("9") <= 57 ---> True
48 <= ord("a") <= 57 ---> False
48 <= ord("G") <= 57 ---> False
48 <= ord("ab") <= 57 ---> Error
Nobody saw anything.
+ 1
Regex?
Here is one example:
https://code.sololearn.com/cmqeW8auv610/?ref=app
0
A = input()
C = 0
for i in A:
if i.isdigit():
C += 1
print(C, "digits are in your input")
0
Hehe 69 views