對於第三個elif,我試圖讓它檢測'Numb'中是否有任何特殊字符,並且是否有重複的while循環。如何查找輸入中是否有任何特殊字符
我一直在使用re.match與進口重新嘗試,但它似乎並不奏效
Numb = input('Enter the number you want to find the factorial of: ')
if Numb.isalpha() == True:
print ('You can\'t find the factorial of a letter stupid! Try a digit
next time')
elif int(Numb) <0:
print ('You cannot find the factorial of a negative number')
elif Numb >=0 and Numb.isdigit() == True:
print ('::::::::::::::::' ':'*len(Numb))
print ('you have chosen', Numb)
print ('::::::::::::::::' ':'*len(Numb))
Con +=1
elif re.match("^[a-zA-Z0-9]*$", Numb):
print ('Do not enter any special characters. e.g. \' \' or \'.\'')
else:
print ('Please entar an integer that is 0 or above')
任何幫助將不勝感激,我仍然很新的這
你的輸入是什麼? – anupsabraham
發生了什麼,你想要發生什麼? – mrCarnivore
1.使用小寫變量名; 2.不要使用'condition == True' – Dabiuteef