救急孩子,计算机导论作业。程序要求输入一个服127到127之间的十进制整数,输出一个八位的二进制整数
x=int(input())
r=0
L=[]
flag =0
if(x<-127 or x > 127):
print("wrong input")
else:
if(x>0):
print("{:0>8o}".format(x)) ## :0>8o 指的是把整型x以八进制输出, 其中o表示8进制,8表示输出8位位宽
elif(x<0 and x!= -1):
print("1{:0>7o}".format(abs(x))) ## 这个是输出7位位宽的八进制数,因为是负数,所以首位加1
else:
print("11111111")