Skip to content

Instantly share code, notes, and snippets.

@dhirabayashi
Last active August 21, 2018 09:22
Show Gist options
  • Save dhirabayashi/a591e2d5e5814e0f42a842ad4de87069 to your computer and use it in GitHub Desktop.
Save dhirabayashi/a591e2d5e5814e0f42a842ad4de87069 to your computer and use it in GitHub Desktop.
import re
while True:
print('文字を一文字入力してください >', end='')
char = input().rstrip()
if len(char) != 1:
print('入力可能な文字は一文字です')
continue
if re.match('[a-z]', char):
upperChar = char.upper()
print('入力値: {}, 文字コード: {}, 大文字: {}, 大文字の文字コード: {}'
.format(char, ord(char), upperChar, ord(upperChar)))
break
elif re.match('[A-Z]', char):
lowerChar = char.lower()
print('入力値: {}, 文字コード: {}, 小文字: {}, 小文字の文字コード: {}'
.format(char, ord(char), lowerChar, ord(lowerChar)))
break
elif re.match('[あ-ん]', char) or re.match('[0-9]', char):
print('入力値: {}, 文字コード: {}'.format(char, ord(char)))
break
else:
print('アルファベット[a-z][A-Z]、ひらがな[あ-ん]、数字[0-9]のいずれかを入力して下さい')
while True:
print('入力値の進数を選択してください(2, 10, 16) > ', end='')
from_radix = int(input())
print('変換したい数値を入力してください > ', end='')
num = int(input(), from_radix)
print('どの進数に変換するか選択してください > ', end='')
to_radix = int(input())
if to_radix == 2:
print(bin(num))
elif to_radix == 8:
print(oct(num))
elif to_radix == 10:
print(num)
elif to_radix == 16:
print(hex(num))
else:
print('その進数には変換できません')
print('続行しますか? (1: 続行 その他: 終了) > ', end='')
flg = input().rstrip()
if flg != '1':
break
print('数値を3つ入力してください')
print('1つ目 > ', end='')
a = int(input())
print('2つ目 > ', end='')
b = int(input())
print('3つ目 > ', end='')
c = int(input())
a, b, c = sorted([a, b, c])
# 三角形になるかどうか
if c < (a + b):
# 正三角形か
if a == b == c:
print('正三角形')
else:
# 直角三角形か
right_angled = a * a + b * b == c * c
# 二等辺三角形か
isosceles = a == b or b == c or c == a
if right_angled and isosceles:
print('直角二等辺三角形')
elif right_angled and not isosceles:
print('直角三角形')
elif not right_angled and isosceles:
print('二等辺三角形')
else:
print('普通の三角形')
else:
print('これは三角形にはならない')
for i in range(10):
for j in range(i + 1):
print(' ', end='')
if i == 0:
for k in range(20):
print('*', end='')
else:
for l in range(2):
print('*', end='')
for m in range((10 - i) * 2 - 4):
print(' ', end='')
if i != 9:
for n in range(2):
print('*', end='')
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment