鱼C论坛

 找回密码
 立即注册
查看: 2189|回复: 6

通过输入数字来输出方向的一个题目

[复制链接]
发表于 2021-3-6 19:27:50 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
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.
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-3-6 19:28:27 | 显示全部楼层
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
except ValueError:
    print('Incorrect input, giving up.')
    sys.exit()

# INSERT YOUR CODE HERE
给了这些提示
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-3-6 19:29:34 | 显示全部楼层
Enter an integer between 1 and 4 and a positive integer: 1 0
Ok, you want to first look this way: &#8679;
In base 3, the second input reads as: 0
So that's how you want to go: &#8679;
Let's go then!
&#8679;
这是其中一个测试。。。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-3-6 19:30:05 | 显示全部楼层
有大佬指点一下吗,,毫无头绪
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 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()
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-3-9 13:17:00 | 显示全部楼层
牛逼啊铁子,我试一下
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-3-9 13:19:40 | 显示全部楼层

可以加一下你微信不,我发不了私信,他的那个题目还要带三进制进去,很麻烦的,我私信发给你看看
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-1-16 09:04

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表