homework help | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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 Respostas
+ 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