![]() |
#2
fall_bernana2019-11-27 15:59
以下是引用LanXX在2019-11-27 14:51:15的发言: 谢谢各位大神,帮帮我,我需要的的确是整数,但怎么才可以输入了字符串也不会出错呢? print('You enter a dark room with two doors.\nDo you go through oor #1 or door #2?') door = int(input('>')) if door == 1: print('There\'s a giant bear here eating a cheese cake.') print('what do you do?') print('1.Take the cake. \n2.Scream at the bear.') num = int(input('>')) for i in range(1): if num == 1: print('The bear eats your face off.\tGood job!') if num == 2: print('The bear eats your legs off.\tGood job!') else: print(f'{num} is not option, do it agains.') continue else: print('you\'re dead') ![]() print('You enter a dark room with two doors.\nDo you go through oor #1 or door #2?') door = input('>') while not door.isdigit(): print("must int\n") door = input('>') if int(door) == 1: print('There\'s a giant bear here eatinsg a cheese cake.') print('what do you do?') print('1.Take the cake. \n2.Scream at the bear.') num = input('>') while not num.isdigit(): print("must int\n") num = input('>') for i in range(1): if int(num) == 1: print('The bear eats your face off.\tGood job!') elif int(num) == 2: print('The bear eats your legs off.\tGood job!') else: print(f'{num} is not option, do it agains.') continue else: print('you\'re dead') |
谢谢各位大神,帮帮我,我需要的的确是整数,但怎么才可以输入了字符串也不会出错呢?
print('You enter a dark room with two doors.\nDo you go through oor #1 or door #2?')
door = int(input('>'))
if door == 1:
print('There\'s a giant bear here eating a cheese cake.')
print('what do you do?')
print('1.Take the cake. \n2.Scream at the bear.')
num = int(input('>'))
for i in range(1):
if num == 1:
print('The bear eats your face off.\tGood job!')
if num == 2:
print('The bear eats your legs off.\tGood job!')
else:
print(f'{num} is not option, do it agains.')
continue
else:
print('you\'re dead')