NP9 十六进制数字的大小牛客网python答案(已测试通过)

 校招时部分企业笔试将禁止编程题跳出页面,为提前适应,练习时请使用在线自测,而非本地IDE。

描述

计算的世界,除了二进制与十进制,使用最多的就是十六进制了,现在使用input读入一个十六进制的数字,输出它的十进制数字是多少?

输入描述:

input读入一个十六进制数字,按照字符串的形式包括数字0-9、字母A-F。

输出描述:

输出读入数字的十进制大小。

示例1

输入:

A

复制输出:

10
pp=str(input())
bk=[]
for i in pp:
    if i=='A':
        i=10
    if i=='B':
        i=11
    if i=='C':
        i=12
    if i=='D':
        i=13
    if i=='E':
        i=14
    if i=='F':
        i=15

    bk.append(int(i))
l=len(bk)
sum=0
for i in range(0,l):
   
    sum=sum+bk[i]*(16**(l-1-i))

print(sum)

 NP10 牛牛最好的朋友们

name1=input()
name2=input()
print(name1+name2)

NP11 单词的长度

pp=input()
print(len(pp))

NP12 格式化输出(二)

pp=input()
print(pp.lower())
print(pp.upper())
print(pp.title())

NP13 格式化输出(三)

pp=input()
print(pp.strip())

NP14 不用循环语句的重复输出

描述

牛牛正在学习Python,他想多次输出朋友的名字,但是因为还没有学习循环语句,他不知道该怎么输出,你能够帮助他将输入的朋友的名字重复输出100次吗?(提示:不可以使用循环或者递归语句,使用字符串 * 运算)

输入描述:

输入一个字符串。

输出描述:

输出重复100次之后的字符串,字符串之间没有间隔。

示例1

输入:

Hello

复制输出:

HelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHello
pp=input()
k=''
for i in range(0,100):
    k=k+pp
print(k)

NP15 截取用户名前10位


pp=input()
l=len(pp)
p=''
if l >10:
    pp=pp[0:10]
print(pp)

 NP16 发送offer

offer_list=['Allen','Tom']
print("Allen, you have passed our interview and will soon become a member of our company.")
print("Tom, you have passed our interview and will soon become a member of our company.")
offer_list[1]='Andy'
print("Allen, welcome to join us!")
print("Andy, welcome to join us!")

NP17 生成列表 

pp=input().split(" ")
print(pp)

NP18 生成数字列表

p=input().split(' ')
k=[]
for i in p:
   i=int(i)
   k.append(i)
print(k)


NP19 列表的长度 

pp=input().split(" ")
l=len(pp)
print(l)

NP20 增加派对名单(一)

pp=input().split(" ")
pp.append('Allen')
print(pp)

NP21 增加派对名单(二) 

pp=input().split(' ')
pp.insert(0,'Allen')
print(pp)

NP22 删除简历

pp=input().split(" ")
del pp[0]
print(pp)

NP23 删除好友

pp=input().split(" ")
pk=input()
pp.remove(pk)
print(pp)

NP24 淘汰排名最后的学生

pp=input().split(" ")
for i in range(0,3):
    pp.pop()
print(pp)

NP25 有序的列表 

my_list=['P','y','t','h','o','n']
pp=sorted(my_list)

print(pp)
print(my_list)
my_list.sort(reverse=True)
print(my_list)

NP26 牛牛的反转列表

num=[3,5,9,0,1,9,0,3]

num.reverse()
print(num)

NP27 朋友们的喜好

name = ['Niumei', 'YOLO', 'Niu Ke Le', 'Mona']
friends=[]
friends.append(name)
food=['pizza', 'fish', 'potato', 'beef']
friends.append(food)
number=[3, 6, 0, 3]
friends.append(number)
print(friends)

NP28 密码游戏 

k=input()
pp=[]
for i in range(0,4):
    p=(int(k[i])+3)%9
    pp.append(p)
b=pp[0]
pp[0]=pp[2]
pp[2]=b
a=pp[1]
pp[1]=pp[3]
pp[3]=a
print(f'{pp[0]}{pp[1]}{pp[2]}{pp[3]}')

NP29 用列表实现栈

stack = [1, 2, 3, 4, 5]
pp=int(input())
stack.pop()
print(stack)
stack.pop()
print(stack)
stack.append(pp)
print(stack)

NP30 用列表实现队列

queue = [1, 2, 3, 4, 5]
k1=int(input())
queue.pop(0)
print(queue)
queue.pop(0)
print(queue)
queue.append(k1)
print(queue)

NP31 团队分组

group_list=['Tom', 'Allen', 'Jane', 'William', 'Tony']
print(group_list[:2])
print(group_list[1:4])
print(group_list[3:])



NP32 牛牛的加减器

x=int(input())
y=int(input())
print(x+y)
print(x-y)

NP33 乘法与幂运算

x=int(input())
y=int(input())
print(x*y)
print(x**y)

NP34 除法与取模运算

x=int(input())
y=int(input())
print(int((x-x%y)/y),int(x-((x-x%y)/y)*y))
a=x/y
print("%.2f" % a)

NP35 朋友的年龄是否相等

x,y=input().split()

print(x==y)

NP36 谁的数字大

x,y=input().split()
print(x>y)
print(x

NP37 不低于与不超过

k,x,y=input().split()
print(k<=x)
print(k>=y)

NP38 牛牛的逻辑运算

x,y=map(int,input().split())
print(f"{x and y}\n{x or y}\n{not x}\n{not y}")

NP39 字符串之间的比较

s1=input()
s2=input()
print(s1==s2)
print(s1.lower()==s2.lower())

NP40 俱乐部的成员

pp=input()
p=input()
print(p in pp)

NP41 二进制位运算

x,y=map(int,input().split())
print(f"{x & y}\n{x|y}")

NP42 公式计算器

x,y,z,k=map(int,input().split())
print((x+y)*(z-k))

NP43 判断布尔值

x=input()
if x==1:
    print("Hello World!")
else:
    print("Erros!")

NP44 判断列表是否为空 

my_list=[]
if my_list:
 print("my_list is not empty!")
else:
    print("my_list is empty!")

NP45 禁止重复注册

current_users=['Niuniu','Niumei','GURR','LOLO']
new_users=['GurR','Niu Ke Le','LoLo','Tuo Rui Chi']

for i in new_users:
    if i in current_users or i.upper() in current_users:
       print("The user name "+ i +" has already been registered! Please change it and try again!")
    else:
       print('Congratulations, the user name '+ i+' is available!')

NP46 菜品的价格

dish={'pizza':10,'rice':2,'yogurt':5,'oth':8}
p=input()
if p  not in dish:
    p='oth'
print(dish[p])

NP47 牛牛的绩点

score={"A":4.0,"B":3.0,"C":2.0,"D":1.0,"F":0,}
sum1=0
num=0
a=0
while 1:
    x=input()
    if x=='False':
        break
    
    y=int(input())
    num=num+y
    sum1=sum1+ score[x]*y
    a=sum1/num
print("%.2f" % a)        

NP48 验证登录名与密码

name=input()
password=input()
if name=="admis":
    if password=="Nowcoder666":
        print("Welcome!")
    else:
        print("user id or password is not correct!")
else:
     print("user id or password is not correct!")

NP49 字符列表的长度

my_list=['P', 'y', 't', 'h', 'o', 'n']
print("Here is the original list:")
print(my_list)
print()
print("The number that my_list has is:")
print(len(my_list))

NP50 程序员节

users_list=['Niuniu','Niumei','Niu Ke Le']
for ii in users_list:
    print("Hi, "+ii+"! Welcome to Nowcoder!")
print( "Happy Programmers' Day to everyone!")

NP51 列表的最大与最小

a=[]
for i in range(10,51):
    a.append(i)
print(a)
print(a[0] ,a[-1])

NP52 累加数与平均值

pp=[int(i) for i in input().split()]
l=len(pp)

sum1=0
for i in pp:
    sum1=sum1+i
print(f"{sum1} {int(sum1)/l:.1f}")

NP53 前10个偶数

my_list=list(range(0,19,2))
for i in my_list:
    print(i)

NP54 被5整除的数字

my=list(range(0,51,5))
del my[0]
for i in my:
    print(i)

NP55 2的次方

my_list=[]
for i in range(1,11):
    my_list.append(2**i)
    
for i in my_list:
    print(i)

NP56 列表解析

list=[i for i in range(0,10)]
print(list)

NP57 格式化清单

list1=['apple', 'ice cream', 'watermelon', 'chips', 'hotdogs','hotpot']
while list1:
    list1.pop()
    print(list1)

NP58 找到HR

users_list=['Niuniu','Niumei','HR','Niu Ke Le','GURR' ,'LOLO' ]
for i in users_list:
    if i =='HR':
        print("Hi, HR! Would you like to hire someone?")
    else:
        print( 'Hi, '+i+'! Welcome to Nowcoder!')

 NP59 提前结束的循环

list1=[3, 45, 9, 8, 12, 89, 103, 42, 54, 79]
pp=int(input())
for i in list1:
    if i==pp:
        break
    else:
        print(i)

NP60 跳过列表的某个元素


for i in range(1,16):
    if i==13:
        continue
    else:
        print(i,end=" ")

NP61 牛牛的矩阵相加

list1=[[1,2,3],[4,5,6],[7,8,9]]
n=int(input())
for i in range(0,3):
    for j in range(0,3):

        
      list1[i][j]=list1[i][j]*n
print(list1)

NP62 运动会双人项目

name1=input()
name2=input()
t=(name1,name2)
print(t)

NP63 修改报名名单 

entry_form=('Niuniu','Niumei')
print(entry_form)
try:
    entry_form[1]='Niukele'
except TypeError:
    print('The entry form cannot be modified!')

NP64 输出前三同学的成绩

name=tuple(input().split())

print(name[0:3])

NP 65名单出现的人

mimi=('Tom', 'Tony', 'Allen', 'Cydin', 'Lucy', 'Anna')
pp=input()
print(mimi)
if pp in mimi:
    print('Congratulations!')
else:
    print('What a pity!')

NP66 增加元组的长度

nn=(1,2,3,4,5)
print(nn)
print(len(nn))
mm=(6,7,8,9,10)
print(nn+mm)
print(len(nn+mm))

 NP67 遍历字典

operators_dict={"<":"less than","==":"equal",}
print('Here is the original dict:')

pp=sorted(operators_dict)
for i in pp:
   # print()
    
    print('Operator '+i+' means '+operators_dict[i]+'.')
operators_dict['>']='greater than'
print()

print('The dict was changed to:')
p=sorted(operators_dict)
for i in p:
   # print()
    print('Operator '+i+' means '+operators_dict[i]+'.')

NP68 毕业生就业调查

survey_list=['Niumei','Niu Ke Le','GURR','LOLO']
result_dict={'Niumei': 'Nowcoder','GURR': 'HUAWEI',}
for i in survey_list:
    if i in result_dict.key():
        print('Hi, '+i+'! Thank you for participating in our graduation survey!')
    else:
        print('Hi, '+i+'! Could you take part in our graduation survey?')

NP69 姓名与学号

my_dict_1={'name': 'Niuniu','Student ID': 1,}
my_dict_2={'name': 'Niumei','Student ID': 2,}
my_dict_3={'name': 'Niu Ke Le','Student ID': 3,}
dict_list=[]
dict_list.append(my_dict_1)
dict_list.append(my_dict_2)
dict_list.append(my_dict_3)
for i in dict_list:

  print(i['name']+"'s student id is "+str(i['Student ID'])+'.')

NP70 首都

cities_dict={'Beijing': {'Capital': 'China'},
             'Moscow': {'Capital': 'Russia'},
             'Paris': {'Capital': 'France'},}
p=sorted(cities_dict)
for i in p:
  #  print(cities_dict[i])
    print(i+' is the capital of '+cities_dict[i]['Capital']+'!')

NP71 喜欢的颜色

result_dict={'Allen': ['red', 'blue', 'yellow'],
             'Tom': ['green', 'white', 'blue'],
             'Andy': ['black', 'pink'],}
pp=sorted(result_dict)

for i in pp:
    print(i+"'s favorite colors are:")
    for j in result_dict[i]:
      print(j)

NP72 生成字典


key=input().split()
value=input().split()
dict1=dict(zip(key,value))
print(dict1)

NP73 查字典

dict1={'a': ['apple', 'abandon', 'ant'],
       'b': ['banana', 'bee', 'become'],
       'c': ['cat', 'come'],
       'd': 'down'}
p=input()
for i in dict1[p]:
    print(i,end=" ")

NP74 字典新增

dict1={'a': ['apple', 'abandon', 'ant'],
       'b': ['banana', 'bee', 'become'],
       'c': ['cat', 'come'],
       'd': 'down'}
le=input()
word=input()
dict1[le]=word
print(dict1)

NP75 使用字典计数

pp=input()
l=len(pp)
dict1={}
for i in range(0,l):
    if pp[i] not in dict1:
        dict1[pp[i]]=1
    else:
        dict1[pp[i]]+=1
print(dict1)

NP76 列表的最值运算

pp=[int(i) for i in input().split()]

print(max(pp))
print(min(pp))

NP77 朋友的年龄和

pp=[int(i) for i in input().split()]
num=sum(pp)
print(num)

NP78 正数输出器

p=int(input())
print(abs(p))

NP79 字母转数字

p=input()
print(ord(p))

NP80 数字的十六进制

pp=int(input())
print(hex(pp))

NP81 数字的二进制表示

x=int(input())
print(bin(x))

NP82 数学幂运算

x,y=input().split()
x=int(x)
y=int(y)
print(pow(x,y))
print(pow(y,x))

NP83 错误出现的次数

pp=[int(i) for i in input().split()]

print(pp.count(0))

NP84 列表中第一次出现的位置

pp=input().split()
print(pp.index('NiuNiu'))

NP85 字符的类型比较

pp=input()
print(pp.isalpha())
print(pp.isdigit())
print(pp.isspace())

NP86 字符子串的查找

pp=input()
if 'NiuNiu' in pp:
    print(pp.find('NiuNiu'))
else:
    print(-1)

NP87 子串的数量

pp=input()
print(pp.count("Niu"))

NP88 句子拆分

pp=input().split()
print(pp)

NP89 单词造句

pp=[]
while 1:
    x=input()
    if x=='0':
        break
    pp.append(x)
print(" ".join(pp))
    

NP90 修正错误的字母

p=input()
print(p.replace('*','b'))

 NP91 小数位修正

p=float(input())
print(round(p,2))

NP92 公式计算器

p=input()
print(eval(p))

NP93 创建集合

p=input().split()
pp=set(p)
pp=sorted(pp)


print(pp)

NP94 函数求差

def cal(x,y):
    return x-y
p=int(input())
q=int(input())
print(cal(p,q))
print(cal(q,p))


NP95 兔子的数量

p=int(input())

def fn(n):
    if n==1:
        return 2
    if n==2:
        return 3
    else:
        return fn(n-1)+fn(n-2)
print(fn(p))

NP96 球的表面积

import math
r=[1, 2, 4, 9, 10, 13]
for i in r:
    print("%.2f" %(4*math.pi*i**2))

NP97 班级管理

class Student:
    def __init__(self,name,num,mark,level):
        self.name=name
        self.num=num
        self.mark=mark
        self.level=level
    def __str__(self):
        return (self.name+"'s student number is "+self.num+","+" and his grade is "+self.mark+". He submitted "+str(len(self.level.split()))+" assignments, each with a grade of "+self.level)

name1=input()
num1=input()
mark1=input()
level1=input()
stu=Student(name1,num1,mark1,level1)
print(stu)

NP98 修改属性1

name=input()
salary=int(input())

class Employee:
    def __init__(self,name,salary,age=None):
        self.name=name
        self.salary=salary
        self.age=age
    def printclass(self):
        try:
            if self.age==None: 
                print("Error! No age")
            else:

                print(f"{self.name}'salary is {self.salary}, and his age is {self.age}")
        except  Exception as e:
                return e
e=Employee(name,salary)
e.printclass()
e.age=int(input())

e.printclass()

NP99 修改属性2

name=input()
salary=int(input())

class Employee:
    def __init__(self,name,salary):
        self.name=name
        self.salary=salary
    def printclass(self):
        try:
            print(f"{self.name}'salary is {self.salary}, and his age is {self.age}")
        except :
             print(hasattr(e,'age'))
e=Employee(name,salary)
e.printclass()
setattr(e,'age',int(input()))
e.printclass()

NP100 重载运算

class Coordinate:
    def __init__(self,x,y):
        self.x=x
        self.y=y
    def __str__(self):
        print(f"({self.x}, {self.y})")
    def __add__(self,Coordinate1):
        return Coordinate(self.x+Coordinate1.x,self.y+Coordinate1.y)
x1,y1=list(map(int,input().split()))
c1=Coordinate(x1,y1)
x2,y2=list(map(int,input().split()))
c2=Coordinate(x2,y2)
c=c1.__add__(c2)
c.__str__()

NP101 正则查找网址

import re
str1=input()
result=re.match("https://www", str1, re.I)
print(result.span())

NP102 提取数字电话

import re
pp=input()
print(re.sub('\D','',pp))

NP103 截断电话号码

import re
s=input()
r=re.match('[0-9-]+',s)
print(r.group())

你可能感兴趣的:(java,开发语言)