通过输入数字来输出方向的一个题目
Prompts the user for two integers.The first one should be between 1 and 4, with
1 meaning initially looking North,
2 meaning initially looking East,
3 meaning initially looking South,
4 meaning initially looking West.
The second one should be positive. When written in base 3, its consecutive digits read from left to right represent the directions to take, with
0 meaning going in the direction one is initially looking at,
1 meaning 45 degrees left of the direction one is initially looking at,
2 meaning 45 degrees right of the direction one is initially looking at.
Prints out:
the direction one is originally looking at, as an arrow,
the representation of the second digit in base 3,
the corresponding sequence of directions to take, as arrows,
in case one is originally looking North or South, the path, so the sequence of arrows again, but nicely displayed.
1 mark for the direction one is originally looking at and the sequence of directions to take as arrows, 1 mark for the representation of the second digit in base 3, 1 mark for the path as a sequence of arrows nicely displayed. 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':
raise ValueError
initial_direction = int(initial_direction)
directions = int(directions)
if initial_direction not in {1, 2, 3, 4} or directions < 0:
raise ValueError
except ValueError:
print('Incorrect input, giving up.')
sys.exit()
# INSERT YOUR CODE HERE
给了这些提示 Enter an integer between 1 and 4 and a positive integer: 1 0
Ok, you want to first look this way: ⇧
In base 3, the second input reads as: 0
So that's how you want to go: ⇧
Let's go then!
⇧
这是其中一个测试。。。 有大佬指点一下吗,,毫无头绪 本帖最后由 逃兵 于 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':
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 =
new_initial_direction = initial_direction+direction
if new_initial_direction == 0.5:
new_initial_direction = 4.5
print('Ok, you want to first look this way: ',dic)
print('In base 3, the second input reads as: ',directions)
print("So that's how you want to go: ",dic)
print("Let's go then!")
print(dic)
except ValueError:
print('Incorrect input, giving up.')
sys.exit()
牛逼啊铁子,我试一下 逃兵 发表于 2021-3-7 08:38
可以加一下你微信不,我发不了私信,他的那个题目还要带三进制进去,很麻烦的,我私信发给你看看
页:
[1]