[英]i am trying to validiate a user input whether its is a number or in a given range,trying to remove the history of previous cells
This is the, I am trying to validate a user input whether it is a number or in a given range, but every time it's not in the range or its a word, it creates a new cell to input a number, want to clear the history of previous cells, how?这就是,我正在尝试验证用户输入是数字还是给定范围内,但是每次它不在范围内或不在一个单词中时,它都会创建一个新单元格来输入数字,想要清除以前的细胞史,怎么样?
def validiating_user():
accepted_range = range(0,10)
within_ranges = False
r = 'abcd'
while r.isdigit() == False or within_ranges == False:
r = input('Plase input a number(0-10): ')
if r.isdigit() == False:
print('Please enter a number,not words')
if r.isdigit() == True:
if int(r) in accepted_range:
within_ranges = True
else:
print('Please enter a number in range(0-10)')
return int(r)
print(validiating_user())
Try adding this to your code.尝试将此添加到您的代码中。
import os
os.system('clear') # Where you would like to have the screen cleared
Please try this请试试这个
import os
clear_os = lambda: os.system('clear')
clear_os()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.