🤵♂️ 个人主页: @北极的三哈 个人主页
👨💻 作者简介:Python
领域优质创作者。
📒 系列专栏:《Python入门学习》《牛客题库-Python篇》
🌐推荐《牛客网》——找工作神器
|笔试题库
|面试经验
|实习经验内推
,求职就业一站解决
str = "Hello World!"
print(str)
str1 = 'Hello World!'
str2 = 'Hello Nowcoder!'
print(str1)
print(str2)
str = input("")
print(str)
a = int(input())
print(a)
print(type(a))
name = input()
print('I am %s and I am studying Python in Nowcoder!' % name)
x=float(input())
print('%0.2f'%x)
Python基本数据类型
### NP7 小数化整数
在线编程跳转链接
number = float(input())
print(int(number))
a = float(int(input()))
print(f'{a:.1f}', type(a), sep='\n')
num=input()
num=int(num,16)
print(num)
a = input()
b = input()
print("".join([a,b]))
print(len(input())
name = input()
print(f'{name.lower()}')
print('%s'%name.upper())
print('{}'.format(name.title()))
name = input()
print(name.strip())
print(input()*100)
s = input()
print(s[0:10])
offer_list = ['Allen', 'Tom']
for i in range(len(offer_list)):
print('{}, you have passed our interview and will soon become a member of our company.'.format(offer_list[i]))
for str_i in offer_list:
if str_i == 'Tom':
print('Andy, welcome to join us!' )
else:
print('{}, welcome to join us!'.format(str_i) )
print(input().split(" "))
print([int(i) for i in input().split(" ")])
print(len(input().split(" ")))
lst = input().split(" ")
lst.append('Allen')
print(lst)
lst = input().split(" ")
lst.insert(0, 'Allen')
print(lst)
lst = input().split(" ")
lst.pop(0)
print(lst)
lst = input().split(" ")
l = input()
lst.remove(l)
print(lst)
name = input().split(" ")
for i in range(3):
name.pop(-1)
print(name)
my_list = ['P','y','t','h','o','n']
print(sorted(my_list))
print(my_list)
my_list.sort(reverse=True)
print(my_list)
num = [3, 5, 9, 0, 1, 9, 0, 3]
num.reverse()
print(num)
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)
num = input()
ls = []
for i in num:
ls.append((int(i)+3)%9)
print(f"{ls[2]}{ls[3]}{ls[0]}{ls[1]}")
stack = [1, 2, 3, 4, 5]
stack.pop(-1)
print(stack)
stack.pop(-1)
print(stack)
num = eval(input())
stack.append(num)
print(stack)
queue = [1, 2, 3, 4, 5]
queue.pop(0)
print(queue)
queue.pop(0)
print(queue)
num = eval(input())
queue.append(num)
print(queue)
group_list = ['Tom', 'Allen', 'Jane', 'William', 'Tony']
print(group_list[0:2])
print(group_list[1:4])
print(group_list[3:5])
x=int(input())
y=int(input())
print(x+y)
print(x-y)
x = int(input())
y = int(input())
print(x*y)
print(x**y)
x = int(input())
y = int(input())
print(x//y, end=" ")
print(x%y)
print('{:.2f}'.format(x/y))
x, y = map(int,input().split(" "))
print(x==y)
x, y = map(int, input().split(" "))
print(x>y, x<y, sep="\n")
k, x, y = input().split(" ")
print(k <= x)
print(k >= y)
x, y = input().split(" ")
x, y = int(x), int(y)
print(x and y)
print(x or y)
print(not x)
print(not y)
s1 = input()
s2 =input()
print(s1 == s2)
print(bool(s1.lower() == s2.lower()))
s = input().split(" ")
name = input()
print(name in s)
x, y = map(int, input().split(" "))
print(x & y)
print(x | y)
x, y, z, k = map(int, input().split(" "))
print((x+y)*(z-k))
x = int(input())
if x == 1:
print("Hello World!")
else:
print("Erros!")
my_list = []
if len(my_list) == 0:
print('my_list is empty!')
else:
print('my_list is not empty!')
#为了不区分大小写把判断的都转成大写
current_users=[i.upper() for i in ['Niuniu','Niumei','GURR','LOLO']]
#因为输出的字符串要保持原来的样子,这个列表内容不能改
new_users=['GurR','Niu Ke Le','LoLo','Tuo Rui Chi']
for i in new_users:
# 通过upper()来调整大写后再判断
if i.upper() in current_users:
print(f"The user name {i} has already been registered! Please change it and try again!")
else:
print(f"Congratulations, the user name {i} is available!")
s = input()
if s == 'pizza':
print(10)
elif s == 'rice':
print(2)
elif s == 'yogurt':
print(5)
else:
print(8)
d = {'A': 4.0, 'B': 3.0, 'C': 2.0, 'D': 1.0, 'F': 0}
s = 0
c = 0
while True:
grade = input()
if grade == "False":
break
credit = int(input())
c += credit
s += d.get(grade)*credit
print('{:.2f}'.format(s/c))
id = input()
password = input()
if id == 'admis' and password == 'Nowcoder666':
print('Welcome!')
else:
print("user id or password is not correct!")
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))
users_list = ['Niuniu', 'Niumei', 'Niu Ke Le']
for i in users_list:
print(f'Hi, {i}! Welcome to Nowcoder!')
print("Happy Programmers' Day to everyone!")
ls = [i for i in range(10, 51)]
print(ls)
print(ls[0], ls[-1])
ls = list(map(int, input().split(" ")))
s = 0
for i in ls:
s += i
print("{} {:.1f}".format(s, s/len(ls)))
my_list = [i for i in range(0, 20) if i%2==0]
for i in my_list:
print(i)
my_list = [i for i in range(1, 51) if i % 5 == 0]
for i in my_list:
print(i)
my_list = []
for i in range(1, 11):
my_list.append(2**i)
for i in my_list:
print(i)
ls = [i for i in range(10)]
print(ls)
ls = ['apple', 'ice cream', 'watermelon', 'chips', 'hotdogs', 'hotpot']
while True:
ls.pop(-1)
print(ls)
if len(ls) == 0:
break
users_list = ['Niuniu', 'Niumei', 'HR', 'Niu Ke Le', 'GURR', 'LOLO']
for i in users_list:
if i == 'HR':
print(f'Hi, {i}! Would you like to hire someone?')
else:
print(f'Hi, {i}! Welcome to Nowcoder!')
ls = [3, 45, 9, 8, 12, 89, 103, 42, 54, 79]
x = eval(input())
for i in ls:
if i == x:
break
print(i)
for i in range(1, 16):
if i == 13:
continue
print(i, end=" ")
n = int(input())
print([[j*n for j in i] for i in [[1, 2, 3], [4, 5, 6], [7, 8, 9]]])
元组学习链接:http://t.csdn.cn/RqgMt
t = (input(), input())
print(t)
entry_form = ('Niuniu', 'Niumei')
print(entry_form)
try:
entry_form[1] = 'Niukele'
except:
print('The entry form cannot be modified!')
s = input().split(' ')
t = tuple(s)
print((t[0:3]))
t = tuple(['Tom', 'Tony', 'Allen', 'Cydin', 'Lucy', 'Anna'])
print(t)
name = input()
if name in t:
print('Congratulations!')
else:
print('What a pity!')
t = tuple(range(1, 6))
print(t)
print(len(t))
t1 = t + tuple(range(6, 11))
print(t1)
print(len(t1))
# 创建一个字典 operators_dict
operators_dict = {'<': 'less than','==': 'equal'}
# 先打印一行
print('Here is the original dict:')
# 在使用 for 循环 遍历 使用 sorted 函数 排序 包含 operators_dict 所有键值对的列表
for key, value in sorted(operators_dict.items()):
# 输出类似字符串
print(f'Operator {key} means {value}.')
# 增加键值对
operators_dict['>'] = 'greater than'
# 输出一个换行
print()
# 在打印一行字符串
print('The dict was changed to:')
# 再来个和上述一样的for循环
for key, value in sorted(operators_dict.items()):
print(f'Operator {key} means {value}.')
survey_list = ['Niumei', 'Niu Ke Le', 'GURR', 'LOLO']
result_dict = {'Niumei': 'Nowcoder', 'GURR': 'HUAWEI'}
for i in survey_list:
if i in result_dict.keys():
print(f'Hi, {i}! Thank you for participating in our graduation survey!')
else:
print(f'Hi, {i}! Could you take part in our graduation survey?')
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:
key, value = i['name'], i['Student ID']
print(f"{key}'s student id is {value}.")
cities_dict = {'Beijing': {'capital': 'China'},
'Moscow': {'capital': 'Russia'},
'Paris': {'capital': 'France'}}
for city in sorted(cities_dict.keys()):
city_value = cities_dict[city]
for item in city_value:
print(f'{city} is the {item} of {city_value[item]}!')
result_dict = {
'Allen': ['red', 'blue', 'yellow'],
'Tom': ['green', 'white', 'blue'],
'Andy': ['black', 'pink']
}
for i in sorted(k for k in result_dict):##列表生成式生成key的列表
print("%s's favorite colors are:" % i)
for x in result_dict[i]:
print(x)
a =input()
b = input()
names = a.split()
language = b.split()
dict_a = dict(zip(names,language))
print(dict_a)
dict1 = {'a': ['apple', 'abandon', 'ant'], 'b': ['banana', 'bee', 'become'], 'c': ['cat', 'come'], 'd': 'down'}
a = input()
for i in dict1[a]:
print(i,end=' ')
letter = input()
word = input()
d = {
"a": ["apple", "abandon", "ant"],
"b": ["banana", "bee", "become"],
"c": ["cat", "come"],
"d": "down",
letter: word,
}
d[letter] = word
print(d)
list1=list(input())
dict1={}
for i in list1:
if i in dict1:
dict1[i]+=1
else:
dict1[i]=1
print(dict1)
s = input().split(" ")
ls = []
for i in s:
ls.append(int(i))
print(max(ls), min(ls), sep = '\n')
ls = [int(i) for i in input().split(" ")]
print(sum(ls))
n = eval(input())
print(abs(n))
print(ord(input()))
print(hex(int(input())))
print(bin(int(input())))
x, y = list(map(int, input().split(" ")))
print(pow(x, y))
print(pow(y, x))
s = input().split(" ")
print(s.count("0"))
s = list(input().split(" "))
print(s.index('NiuNiu'))
s = input()
print(s.isalpha())
print(s.isdigit())
print(s.isspace())
long_str = input()
print(long_str.find('NiuNiu'))
patten = input()
print(patten.count('Niu'))
s = input()
print(s.split(' '))
lst = []
while True:
w = input()
if w == '0':
break
lst.append(w)
print(' '.join(lst))
s = input()
print(s.replace('a*', 'ab'))
f = float(input())
print(round(f, 2))
s = eval(input())
print(s)
s = input().split(' ')
print(sorted(set(s)))
def cal(a, b):
return a - b
x = int(input())
y = int(input())
print(cal(x, y))
print(cal(y, x))
def f(n):
if n==1:
return 2
if n==2:
return 3
else:
return f(n-1)+f(n-2)
n=int(input())
print(f(n))
import math as mt
def vol(n):
return 4*mt.pi*(n**2)
list1=[1, 2, 4, 9, 10, 13]
for n in list1:
print(round(vol(n),2))
class Student:
def __init__(self, name, stu_num, score, grade):
self.name = name
self.stu_num = stu_num
self.score = score
self.grade = grade
#__str__方法用于返回对象的描述信息,如果不使用__str__方法,直接print,或者return,返回的是对象的内存地址。
def __str__(self):
return ("%s's student number is %s, and his grade is %d. He submitted %s assignments, each with a grade of %s"
% (self.name, self.stu_num, int(self.score), len(self.grade.split()), self.grade))
name1 = input()
stu_num1 = input()
score1 = input()
grade1 = input()
stu = Student(name1, stu_num1, score1, grade1)
print(stu)
class employee:
def __init__(self,name,salary,age=-1):
self.name=name
self.salary=salary
self.age=age
def printclass(self):
if self.age==-1:
print("Error! No age")
else:
print("{}'salary is {}, and his age is {}".format(self.name,self.salary,self.age))
a=input()
b=int(input())
c=int(input())
e=employee(a,b)
e.printclass()
e.age=c
e.printclass()
class Employee():
def __init__(self, name, salary) -> None:
self.name = name
self.salary = salary
def printclass(self):
print(f"{self.name}'salary is {self.salary}, and his age is {self.age}")
name = input()
salary = int(input())
age = int(input())
e = Employee(name, salary)
if hasattr(e,'age'):
e.printclass()
else:
print(False)
setattr(e,"age",age)
e.printclass()
class Coordinate():
def __init__(self, x, y):
self.x = x
self.y = y
def __str__(self):
print((self.x, self.y))
def __add__(self):
self.x = x1 + x2
self.y = y1 + y2
x1, y1 = map(int, input().split()) # 1.输入第一行两个数字
x2, y2 = map(int, input().split()) # 1.输入第二行两个数字
c1 = Coordinate(x1, y1) # 2. 调用类
c1.__add__() # 3. 调用__add__()函数,实现两组数据分别对应相加
c1.__str__() # 4. 调用__str__()函数,打印(相加之后的x, 相加之后的y)
import re
http = input()
result = re.match('https://www',http,re.I)
print(result.span())
import re
#导入模块
p=r'[-A-Za-z]+'
#第一个‘-’表示字符‘-’,A-Za-z表示匹配大小字母
#‘+’号表示连续匹配
text=input()
#输入测试字符串
print(re.sub(p,'',text))
#利用sub()函数过滤再输出
import re
s = input()
r = re.match('[0-9-]+',s)
print(r.group())
推 荐:牛客题霸-经典高频面试题库
🌐
找工作神器-|笔试题库|面试经验|大厂面试题
👉 点击链接进行注册学习