第一题 输出Hello World

print("Hello World")

第二题
输入两个整数A、B,输出它们的和

a = int(input())
b = int(input())
c = a+b
print(c)

第三题
输入一个浮点数和一个整数,计算保留n位小数的四舍五入的值

 = float(input())
b = int(input())
print(round(a,b))

第四题
输入两个正整数,输出他们各自的二进制和逻辑与运算

a = int(input())
b = int(input())
c= a & b
print(bin(a),bin(a),c,end = '')

第五题
输入一个整数n和一个字符a,输出n对应的ASCll 码值和a的ASCll 码值。

a = int(input())
b = input()
print(chr(a),ord(b))

第六题
输入一个整数,输出它的十六进制,八进制,二进制

a = int(input())
print(oct(a),hex(a),bin(a),sep = ',')

第七题
输入一个负整数,输出4行格式输出结果

a = int(input())
b = abs(a);
print('{:<10}'.format(a))
print('{:>10}'.format(a))
print('{:<10}'.format('+%d'%b))
print('{:>10}'.format('+%d'%b))

第八题
输入一个浮点数,输出它的4个格式结果

a = float(input())
print(round(a,6),round(a,2),round(a,8),'{:.6e}'.format(a),'{:,}'.format(a),sep='/')

第九题
输入一个整数,输出它的各种进制表示

a = int(input())
print('{:b}'.format(a),'{:o}'.format(a),'{:#o}'.format(a),'{:x}'.format(a),'{:#x}'.format(a),'{:#X}'.format(a),sep = ',')

第十题
输入整数m和n,输出n位长的m的二进制,若n超出实际长度,则左边填充0

a = int(input())
b = int(input())
c = int('{:b}'.format(a))
d = c
count = 0
while d > 0:count = count+1d = d//10
if count < b:for i in range(b-count):print('0',end= '')print(c)
else :print(c)

第十一题
将一个直角坐标转换为极坐标

import cmath
a = int(input())
b = int(input())
cn = complex(a,b)
ret = cmath.polar(cn)
print('{:.4f}'.format(ret[0]),'{:.4f}'.format(ret[1]),sep = ',')

第十二题
将一个浮点数转为比率

a = float(input())
b = int(a*10)
c = 10
d = 1
if b%2==0 and c%2==0:b = b//2c = c//2print(b,c,sep='/')
elif b%5==0 and c%5==0:b = b//5c = c//5print(b,c,sep='/')
else:print(b,d,sep='/')

第十三题
勾股定理

import math
a = int(input())
b = int(input())
max = a if a > b else b
min = a if a < b else b
def isTriangle(a, b, c):  # 判断是否三角形if a + b > c and a + c > b and b + c > a and abs(a - b) < c and abs(a - c) < b and abs(c - b) < a:return Trueelse:return False
condition1 = int(math.sqrt(math.pow(max, 2) - math.pow(min, 2)))
condition2 = int(math.sqrt(math.pow(max, 2) + math.pow(min, 2)))
if isTriangle(min, max, condition2) and math.pow(min, 2) + math.pow(max, 2) == math.pow(condition2,2) and condition2 > max:print("c")
elif isTriangle(min, max, condition1) and math.pow(min, 2) + math.pow(condition1, 2) == math.pow(max, 2):if condition1 < min:print("a")if max > condition1 > min:print("b")
else:print("non")

第十四题
对一个浮点数f指定n位小数输出且四舍五入

a = float(input())
n = int(input())
print(round(a,n))

第十五题
输入经纬度计算距离

import math
lat1 = float(input())  #lat 纬度 lon 经度
lon1 = float(input())
lat2 = float(input())
lon2 = float(input())
result = (1-math.cos(math.radians(lat2-lat1)))/2 + math.cos(math.radians(lat1)) * math.cos(math.radians(lat2)) * ((1-math.cos(math.radians(lon2-lon1)))/2)
d = 2 * math.asin(math.sqrt(result)) * 6371
print("%.4fkm" % d)

第十六题
风寒指数

import math
v = float(input())
T = float(input())
W = 13.12 + 0.6215 * T - 11.35 * math.pow(v, 0.16) + 0.3965 * T * math.pow(v, 0.16)
print(round(W))

第十七题
输入两个分数,计算加减乘除

import fractions
a = int(input())
b = int(input())
c = int(input())
d = int(input())
num1 = fractions.Fraction(a, b)
num2 = fractions.Fraction(c, d)
temp = num1 + num2
print("(", num1, ")+(", num2, ")=", temp, sep='')
temp = num1 - num2
print("(", num1, ")-(", num2, ")=", temp, sep='')
temp = num1 * num2
print("(", num1, ")*(", num2, ")=", temp, sep='')
temp = num1 / num2
print("(", num1, ")/(", num2, ")=", temp, sep='')

第十八题
计算圆柱体积和面积

import math
h = float(input())
r = float(input())
v = math.pi * math.pow(r,2) * h
s = 2 * math.pi * math.pow(r,2) + 2 * math.pi * r * h
print("%.4f"% v)
print("%.4f"% s)

第十九题
计算狗的年龄

def getYear(year):a = 10.5if year == 0:return 0elif year == 1:return aelif year == 2:return 2 * aelse:ret = (year - 2) * 4 + 2 * a return ret
n = int(input())
y = getYear(n)
print(int(y))

第二十题
RGB转换HSV

def rgb2hsv(R, G, B):R, G, B = R / 255.0, G / 255.0, B / 255.0  # R,G,B在 0 到 1 之间Max = max(R, G, B)  # 最大值Min = min(R, G, B)  # 最小值m = Max - MinV = Maxif V == 0:S = 0else:S = m / Maxif Max == Min:H = 0elif Max == R:H = ((G - B) / m) * 60elif Max == G:H = ((B - R) / m) * 60 + 120elif Max == B:H = ((R - G) / m) * 60 + 240if H < 0:H = H + 360return H, S, V
r = int(input())
g = int(input())
b = int(input())
h, s, v = rgb2hsv(r, g, b)
print("%.4f" % h, "%.4f%%" % (s * 100), "%.4f%%" % (v * 100), sep=",")

PythonNOJ习题前二十道(西北工业大学cpSkill实验平台)相关推荐

  1. 西北工业大学matlab安装,西北工业大学Matlab实验报告.doc

    PAGE PAGE 21 西北工业大学 <基于MATLAB的数字信号处理>实验报告 学 院: 计算机学院 学 号: 姓 名: 专 业: 计算机科学与技术 西北工业大学 2017年 07 月 ...

  2. 怒刷python作业(西北工业大学cpSkill平台)

    以下作业题仅为参考答案,为了锻炼思维的目的,尽量多的自己实现功能少引包,大家对题有更好的思路和更方便的包欢迎大家多多留言,祝愿大家共同进步 1.hello word 略- 2.A+B A = int( ...

  3. 伟人必须回答的(二十道问题)

    二十道问题如果你喜欢写东西的话,尝试完成下面这个简单的自我测试问卷. 这份问卷是由职业指导专家詹姆斯··戈尼亚()提出的.詹姆斯是年在美国在线()上推广在线职业指导的先行者.下面,请依次写下每一道题的 ...

  4. TIOBE 8 月榜单:Groovy 和 Objective-C 重返前二十

    点击上方蓝色"程序猿DD",选择"设为星标" 回复"资源"获取独家整理的学习资料! 来源 | https://www.oschina.net ...

  5. zoomeye爬取前二十页ip+port记录

    手速慢?刷洞刷不过别人?怎么办? get一键爬取zoomeye前二十页 妈妈再也不用担心我刷洞刷不过别人了 首先进入zoomeye 打开我祖传多年的大bp进行抓包 看到返回的是json数据 思路来了用 ...

  6. 人口流向数据_中国人口流入流出前二十的城市(2019)

    中国人口流入流出前二十的城市 (2019) 根据 2019 年的第六次人口普查数据,最近 5 年来向长三角地区迁移的人口主要来自 河南.安徽.四川.江西:从长三角地区迁移外出的人口主要方向是北京.广东 ...

  7. Java求8+88+888+8888········的前二十项和

    首先,我们分析这道题,从一个8一直加到二十个8,肯定要考虑到最后获取值的取值范围而long类型的最大值为9223372036854775807,很明显求二十个8的范围超出了long类型的范围. 检测代 ...

  8. 保定市计算机高中学校排名,2021保定高中学校排名前二十

    2021保定高中学校排名前二十2021-05-07 16:54:29文/樊越 很多同学都十分关心高中的排名情况,那么保定有哪些比较好的高中?它们的排名又是如何呢? 保定高中排名前二十排名学校 1蠡县南 ...

  9. 客观的评价西北工业大学

    怎样的评价才叫客观呢?量化,以及凭着良心说话.我在西工大呆了3年,但请相信,我所说的绝对不会带有任何感情色彩,我只是作为一名学生客观的评价西工大,我的母校. 在上大学前有很多人对我说,如果你要评价一所 ...

最新文章

  1. 计算机丢失filter.dll,AxCoFilter.dll
  2. 《3D数学基础系列视频》1.1向量基本概念
  3. DotNetty 实现 Modbus TCP 系列 (二) ModbusFunction 类图及继承举例
  4. oracle中存储过程可见权限,Oracle数据库存储过程与权限
  5. display none的元素重新展示如何撑开页面_寻根问底之——元素隐藏你知多少?
  6. C++11 并发指南五(std::condition_variable 详解)
  7. 2021-9-30 Python Teaching Note
  8. python写ini文件不能保持原有顺序问题_python 生成 xml文件 属性的顺序问题
  9. bash配置文件的修改
  10. Javascript第二章中switch结构及与if的区别第二课
  11. 直流稳压电源的设计与制作
  12. [渝粤教育] 西南科技大学 机械工程测试技术 在线考试复习资料
  13. MATLAB 函数画图
  14. openwrt下部署adbyby去广告大师 免luci 带自启动,自动开启透明代理
  15. 9个最适合Elementor的免费主题【官方推荐】
  16. “木兰”致歉背后的思考,为什么物联网也能用Python
  17. 安装vue环境,并新建Vue项目
  18. health_parent的linux环境
  19. 哈工大计算机网络Mooc 第八章笔记(网络层(中))
  20. VR全景图片,助力VR全景制作,720全景效果图

热门文章

  1. html p行间距离 p标签上下行间距CSS设置
  2. 基于遗传算法的卷积神经网络架构搜索
  3. 一本通OJ 1034:计算三角形面积
  4. 初一知识用计算机进行运算,【初一数学】必考的21个知识点!
  5. Mac 下编译 libmono.so 和 DLL 加密详解
  6. 那些像段子一样的生活经历1csdn
  7. Linux安装Discuz论坛(centos 7)
  8. EBAZ4205矿卡控制卡
  9. 2021-04-10 粤嵌单片机兴趣课(一)
  10. 东南亚电商Shopee爆款打造小技巧,一定要收藏!