Hugo888 发表于 2021-3-9 19:10:28

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

题目有点长……我分开发
# 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':
      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

Hugo888 发表于 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: ⇧
In base 3, the second input reads as: 0
So that's how you want to go: ⇧
Let's go then!
⇧$ 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: ⇨
In base 3, the second input reads as: 1
So that's how you want to go: ⬀
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: ⇧
In base 3, the second input reads as: 2222
So that's how you want to go: ⬀⬀⬀⬀
Let's go then!
⬀⬀⬀⬀$ 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: ⇧
In base 3, the second input reads as: 1111
So that's how you want to go: ⬁⬁⬁⬁
Let's go then!
⬁⬁⬁⬁
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: ⇧
In base 3, the second input reads as: 22121022020212200
So that's how you want to go: ⬀⬀⬁⬀⬁⇧⬀⬀⇧⬀⇧⬀⬁⬀⬀⇧⇧
Let's go then!
⇧⇧⬀⬀⬁⬀⇧⬀⇧⬀⬀⇧⬁⬀⬁⬀⬀$ 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: ⇧
In base 3, the second input reads as: 2211110221101010202
So that's how you want to go: ⬀⬀⬁⬁⬁⬁⇧⬀⬀⬁⬁⇧⬁⇧⬁⇧⬀⇧⬀
Let's go then!
⬀⇧⬀⇧⬁⇧⬁⇧⬁⬁⬀⬀⇧⬁⬁⬁⬁⬀⬀
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: ⇩
In base 3, the second input reads as: 110020020220
So that's how you want to go: ⬂⬂⇩⇩⬃⇩⇩⬃⇩⬃⬃⇩
Let's go then!
⬂⬂⇩⇩⬃⇩⇩⬃⇩⬃⬃⇩$ 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: ⇩
In base 3, the second input reads as: 21121011101102020200
So that's how you want to go: ⬃⬂⬂⬃⬂⇩⬂⬂⬂⇩⬂⬂⇩⬃⇩⬃⇩⬃⇩⇩
Let's go then!
⬃⬂⬂⬃⬂⇩⬂⬂⬂⇩⬂⬂⇩⬃⇩⬃⇩⬃⇩⇩
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: ⇩
In base 3, the second input reads as: 112222221021020
So that's how you want to go: ⬂⬂⬃⬃⬃⬃⬃⬃⬂⇩⬃⬂⇩⬃⇩
Let's go then!
⬂⬂⬃⬃⬃⬃⬃⬃⬂⇩⬃⬂⇩⬃⇩$ 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: ⇨
In base 3, the second input reads as: 221102100021221002201
So that's how you want to go: ⬂⬂⬀⬀⇨⬂⬀⇨⇨⇨⬂⬀⬂⬂⬀⇨⇨⬂⬂⇨⬀
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: ⇨
In base 3, the second input reads as: 102110001122000
So that's how you want to go: ⬀⇨⬂⬀⬀⇨⇨⇨⬀⬀⬂⬂⇨⇨⇨
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: ⇦
In base 3, the second input reads as: 121222111112012102000
So that's how you want to go: ⬃⬁⬃⬁⬁⬁⬃⬃⬃⬃⬃⬁⇦⬃⬁⬃⇦⬁⇦⇦⇦
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: ⇦
In base 3, the second input reads as: 22022122201121100201112222
So that's how you want to go: ⬁⬁⇦⬁⬁⬃⬁⬁⬁⇦⬃⬃⬁⬃⬃⇦⇦⬁⇦⬃⬃⬃⬁⬁⬁⬁
I don't want to have the sun in my eyes, but by all means have a go at it!

Hugo888 发表于 2021-3-9 19:13:31

乱码是箭头。。发不出图片,就是输入不同的数字,会有箭头出来
页: [1]
查看完整版本: 各位大哥帮帮忙,python三进制的一些问题