vendredi 3 mars 2017

How to check if user has entered a positive integer using isdigit? [duplicate]

This question already has an answer here:

  1. Ask the user to enter a positive integer.

  2. Check the value entered to see if it corresponds to a positive integer.

  3. If the user entered a positive integer do the following:

    • If the integer is even print “You entered an even number”

    • Otherwise if the integer is a multiple of 7 print “You entered an odd number that is a multiple of 7”

    • Otherwise print “You entered an odd number that is NOT a multiple of 7”

  4. Otherwise, print the message ‘You did not enter a valid input!’.

What I have done:

myint = eval(input('Enter a positive integer: '))

if myint % 2 == 0:
    print("You entered an even number")

elif myint % 7 == 0:
    print("You entered an odd number that is a multiple of 7")

else:
    print("You entered an odd number that is NOT a multiple of 7")

elif myint ???
    print("You did not enter a valid input!")

So I need help figuring out how to evaluate the input and if its not a positive integer print("You did not enter a valid input!"). So parts B and D, any suggestions?

SAMPLE OUTPUTS FOR ABOVE CODE

Aucun commentaire:

Enregistrer un commentaire