×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Python
Posted by: Cammy And
Added: Apr 6, 2021 8:56 PM
Views: 3944
Tags: no tags
  1. def prompt(text):
  2.     while True:
  3.         n = input(text)
  4.         try:
  5.             n = int(n)
  6.             if n < 0:
  7.                 continue
  8.             return n # If the input is valid, return n.
  9.         except:
  10.             continue