|
发表于 2021-3-7 08:38:46
|
显示全部楼层
本帖最后由 逃兵 于 2021-3-7 08:41 编辑
- import sys
- try:
- initial_direction, directions = input('Enter an integer between 1 and 4 '
- 'and a positive integer: '
- ).split()
- if len(initial_direction) != 1\
- or len(directions) > 1 and directions[0] == '0':
- raise ValueError
- initial_direction = int(initial_direction)
- directions = int(directions)
- if initial_direction not in {1, 2, 3, 4} or directions < 0:
- raise ValueError
- dic={1:'↑',1.5:'↗',2:'→',2.5:'↘',3:'↓',3.5:'↙',4:'←',4.5:'↖'}
- direction = [0,-0.5,0.5]
- new_initial_direction = initial_direction+direction[directions]
- if new_initial_direction == 0.5:
- new_initial_direction = 4.5
- print('Ok, you want to first look this way: ',dic[initial_direction])
- print('In base 3, the second input reads as: ',directions)
- print("So that's how you want to go: ",dic[new_initial_direction])
- print("Let's go then!")
- print(dic[new_initial_direction])
- except ValueError:
- print('Incorrect input, giving up.')
- sys.exit()
复制代码 |
|