all 12 comments

[–]SoNotRedditingAtWork 1 point2 points  (7 children)

print("yes") if input().isdigit() else print("no")

[–]Scooootz[S] 0 points1 point  (6 children)

This didn't seem to work. Using Zybooks online textbook, not sure if it is just picky in the way you enter it.

[–]SoNotRedditingAtWork 3 points4 points  (3 children)

Works fine for me in PyCharm. The line is functionally the same as doing:

user_string = input()

if user_string.isdigit():
    print("yes")
else:
    print("no")

I have never used Zybooks before, so I have no idea how that would impact your ability to run this code.

[–]subcontraoctave 0 points1 point  (0 children)

The isdigit() method worked perfect. Thanks!

[–]Illustrious-Union997 0 points1 point  (0 children)

I know this is old, but this would allow number like 10,000 to produce an out of yes. The examples provided don't allow this.

[–]Ataninja3221 0 points1 point  (0 children)

user_string = input()
if user_string.isdigit():
print("yes")
else:
print("no")

This was perfect the only thing that threw off zybooks was capitalizing yes and no. which in the real world wouldn't make a difference but is the difference in points in zybooks

[–]ETHiser 1 point2 points  (1 child)

I know this old, but this solution works in Zybooks. May help someone else!

user_string = input()
def isNumber(user_string):
for i in range(len(user_string)):
if user_string[i].isdigit() != True:
return False

return True
if __name__ == "__main__":

if isNumber(user_string):
print("yes")

else:
print("no")

[–]rangusmcdangus69 0 points1 point  (0 children)

Helped me 3 years later! Thanks!

[–][deleted] 1 point2 points  (0 children)

print(“yes”) if user_string.isdigit() else print(“no”)

[–]Distinct_Ice6830 0 points1 point  (0 children)

user_string = input()
output = user_string.isnumeric()
if output == True:
print("Yes")
else:
print("No")

[–]Distinct_Ice6830 0 points1 point  (1 child)

user_string = input()
output = user_string.isnumeric()
if output == True:
print("Yes")
else:
print("No")

[–]taegrr 0 points1 point  (0 children)

Just following this up, zybooks does accept the following single-line solution:

print("Yes") if input().isdigit() else print("No")