-1
我是一個新的程序員,我用了一個解決這個問題所困擾:需要較短/更優雅的解決方案,以蟒蛇while循環
用戶輸入與循環和條件。使用raw_input()提示1至100之間的數字 。如果輸入符合標準,則在屏幕上指示並退出。 否則,顯示錯誤並重新提示用戶,直到收到正確的輸入。
我最後一次嘗試最後的工作,但我想知道你更優雅的解決方案,我的記憶裏感謝所有的輸入:P
n = int(input("Type a number between 1 and 100 inclusive: "))
if 1 <= n <= 100:
print("Well done!" + " The number " + str(n) + " satisfies the condition.")
else:
while (1 <= n <= 100) != True:
print("Error!")
n = int(input("Type a number between 1 and 100: "))
else:
print ("Thank goodness! I was running out of memory here!")
您鍵入的快捷,+1 – paisanco
@ paisanco。如果你看到我打字,你會想知道如何;) –