简体   繁体   中英

How can i get my program to reject letter inputs, and only accept number inputs?

Thank you guys for helping me:) I'm new to Python and really appreciate the helpful responses you guys give

edit - i have solved my problem

here is what i did to solve it

i = False
while i == False:
    Type = input("Please enter a number from 1-6")
    if Type.isdigit():
        i = True
    else:
        i = False

Here is how:

Type = input("Please enter your choice of slab -->")

while True:
    if Type.isdigit():
        break
    Type = input("Please enter a value from 1-6")

try

Type = input("Please enter your choice of slab -->")

checknum = Type.isdigit()

while not checknum:
    Type = int(input("Please enter a value from 1-6"))
    checknum=Type.isdigit()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM