Write a function called getPositiveInteger with no parameter

Write a function called getPositiveInteger with no parameter. The function should contain codes that will ask the user for a positive integer and handle the user input validation that checks whether the integer is positive. It should continue to ask the user to re-enter until a valid answer is received. When a valid answer is received, return the integer. You must use a while loop, and you cannot use \"while True:\" condition.

Solution

def getPositiveInteger():
   p=0
   while p<=0:
       p = int(input(\"Enter a positive integer:\"))
   return p
print(getPositiveInteger())

 Write a function called getPositiveInteger with no parameter. The function should contain codes that will ask the user for a positive integer and handle the us

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site