+ 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

18th Oct 2019, 6:35 AM
Grace Broadworth
Grace Broadworth - avatar
8 ответов
+ 10
Think about the string method isdigit(). It returns True if all characters in a string are digits and False if not.
18th Oct 2019, 8:06 AM
David Ashton
David Ashton - avatar
+ 8
We are here to help you but not on homework, on your problem. So first try to do by yourself.
18th Oct 2019, 7:15 AM
A͢J
A͢J - avatar
+ 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.
18th Oct 2019, 7:39 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 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
19th Oct 2019, 3:59 AM
David Ashton
David Ashton - avatar
+ 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.
18th Oct 2019, 9:20 AM
Seb TheS
Seb TheS - avatar
18th Oct 2019, 9:24 PM
Victor
0
A = input() C = 0 for i in A: if i.isdigit(): C += 1 print(C, "digits are in your input")
18th Oct 2019, 2:46 PM
William M
William M - avatar
0
Hehe 69 views
19th Oct 2019, 2:53 AM
VVill
VVill - avatar