鱼C论坛

 找回密码
 立即注册
查看: 900|回复: 2

各位大哥帮帮忙,python三进制的一些问题

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

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

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

x
题目有点长……我分开发
# Prompts(提示) the user for two integers. #how to define these two integers?
# - The first one should be between 1 and 4, with  #first for direction
#   * 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连贯的#what's base 3?
#   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.#3nary
#
# 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.


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-9 19:11:11 | 显示全部楼层
本帖最后由 Hugo888 于 2021-3-9 19:13 编辑

QUIZ 3
COMP9021 PRINCIPLES OF PROGRAMMING
$ python3 quiz_3.py
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;$ python3 quiz_3.py
Enter an integer between 1 and 4 and a positive integer: 2 1
Ok, you want to first look this way: &#8680;
In base 3, the second input reads as: 1
So that's how you want to go: &#11008;
I don't want to have the sun in my eyes, but by all means have a go at it!
$ python3 quiz_3.py
Enter an integer between 1 and 4 and a positive integer: 1 80
Ok, you want to first look this way: &#8679;
In base 3, the second input reads as: 2222
So that's how you want to go: &#11008;&#11008;&#11008;&#11008;
Let's go then!
&#11008;&#11008;&#11008;&#11008;$ python3 quiz_3.py
Enter an integer between 1 and 4 and a positive integer: 1 40
Ok, you want to first look this way: &#8679;
In base 3, the second input reads as: 1111
So that's how you want to go: &#11009;&#11009;&#11009;&#11009;
Let's go then!
&#11009;&#11009;&#11009;&#11009;
Date: Trimester 1, 2021.
2 COMP9021 PRINCIPLES OF PROGRAMMING
$ python3 quiz_3.py
Enter an integer between 1 and 4 and a positive integer: 1 123456789
Ok, you want to first look this way: &#8679;
In base 3, the second input reads as: 22121022020212200
So that's how you want to go: &#11008;&#11008;&#11009;&#11008;&#11009;&#8679;&#11008;&#11008;&#8679;&#11008;&#8679;&#11008;&#11009;&#11008;&#11008;&#8679;&#8679;
Let's go then!
&#8679;&#8679;&#11008;&#11008;&#11009;&#11008;&#8679;&#11008;&#8679;&#11008;&#11008;&#8679;&#11009;&#11008;&#11009;&#11008;&#11008;$ python3 quiz_3.py
Enter an integer between 1 and 4 and a positive integer: 1 1097393690
Ok, you want to first look this way: &#8679;
In base 3, the second input reads as: 2211110221101010202
So that's how you want to go: &#11008;&#11008;&#11009;&#11009;&#11009;&#11009;&#8679;&#11008;&#11008;&#11009;&#11009;&#8679;&#11009;&#8679;&#11009;&#8679;&#11008;&#8679;&#11008;
Let's go then!
&#11008;&#8679;&#11008;&#8679;&#11009;&#8679;&#11009;&#8679;&#11009;&#11009;&#11008;&#11008;&#8679;&#11009;&#11009;&#11009;&#11009;&#11008;&#11008;
QUIZ 3 3
$ python3 quiz_3.py
Enter an integer between 1 and 4 and a positive integer: 3 240756
Ok, you want to first look this way: &#8681;
In base 3, the second input reads as: 110020020220
So that's how you want to go: &#11010;&#11010;&#8681;&#8681;&#11011;&#8681;&#8681;&#11011;&#8681;&#11011;&#11011;&#8681;
Let's go then!
&#11010;&#11010;&#8681;&#8681;&#11011;&#8681;&#8681;&#11011;&#8681;&#11011;&#11011;&#8681;$ python3 quiz_3.py
Enter an integer between 1 and 4 and a positive integer: 3 2943856728
Ok, you want to first look this way: &#8681;
In base 3, the second input reads as: 21121011101102020200
So that's how you want to go: &#11011;&#11010;&#11010;&#11011;&#11010;&#8681;&#11010;&#11010;&#11010;&#8681;&#11010;&#11010;&#8681;&#11011;&#8681;&#11011;&#8681;&#11011;&#8681;&#8681;
Let's go then!
&#11011;&#11010;&#11010;&#11011;&#11010;&#8681;&#11010;&#11010;&#11010;&#8681;&#11010;&#11010;&#8681;&#11011;&#8681;&#11011;&#8681;&#11011;&#8681;&#8681;
4 COMP9021 PRINCIPLES OF PROGRAMMING
$ python3 quiz_3.py
Enter an integer between 1 and 4 and a positive integer: 3 7970352
Ok, you want to first look this way: &#8681;
In base 3, the second input reads as: 112222221021020
So that's how you want to go: &#11010;&#11010;&#11011;&#11011;&#11011;&#11011;&#11011;&#11011;&#11010;&#8681;&#11011;&#11010;&#8681;&#11011;&#8681;
Let's go then!
&#11010;&#11010;&#11011;&#11011;&#11011;&#11011;&#11011;&#11011;&#11010;&#8681;&#11011;&#11010;&#8681;&#11011;&#8681;$ python3 quiz_3.py
Enter an integer between 1 and 4 and a positive integer: 2 9848289250
Ok, you want to first look this way: &#8680;
In base 3, the second input reads as: 221102100021221002201
So that's how you want to go: &#11010;&#11010;&#11008;&#11008;&#8680;&#11010;&#11008;&#8680;&#8680;&#8680;&#11010;&#11008;&#11010;&#11010;&#11008;&#8680;&#8680;&#11010;&#11010;&#8680;&#11008;
I don't want to have the sun in my eyes, but by all means have a go at it!
$ python3 quiz_3.py
Enter an integer between 1 and 4 and a positive integer: 2 6083235
Ok, you want to first look this way: &#8680;
In base 3, the second input reads as: 102110001122000
So that's how you want to go: &#11008;&#8680;&#11010;&#11008;&#11008;&#8680;&#8680;&#8680;&#11008;&#11008;&#11010;&#11010;&#8680;&#8680;&#8680;
I don't want to have the sun in my eyes, but by all means have a go at it!
$ python3 quiz_3.py
Enter an integer between 1 and 4 and a positive integer: 4 6578987643
Ok, you want to first look this way: &#8678;
In base 3, the second input reads as: 121222111112012102000
So that's how you want to go: &#11011;&#11009;&#11011;&#11009;&#11009;&#11009;&#11011;&#11011;&#11011;&#11011;&#11011;&#11009;&#8678;&#11011;&#11009;&#11011;&#8678;&#11009;&#8678;&#8678;&#8678;
I don't want to have the sun in my eyes, but by all means have a go at it!
QUIZ 3 5
$ python3 quiz_3.py
Enter an integer between 1 and 4 and a positive integer: 4 2349986589476
Ok, you want to first look this way: &#8678;
In base 3, the second input reads as: 22022122201121100201112222
So that's how you want to go: &#11009;&#11009;&#8678;&#11009;&#11009;&#11011;&#11009;&#11009;&#11009;&#8678;&#11011;&#11011;&#11009;&#11011;&#11011;&#8678;&#8678;&#11009;&#8678;&#11011;&#11011;&#11011;&#11009;&#11009;&#11009;&#11009;
I don't want to have the sun in my eyes, but by all means have a go at it!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-3-9 19:13:31 | 显示全部楼层
乱码是箭头。。发不出图片,就是输入不同的数字,会有箭头出来
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-1-16 08:19

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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