问:

基础题:

  1. 从键盘输入4个数字,各数字采用空格分隔,对应为变量x0,y0,x1,y1。计算(x0y0)和(x1,y1)两点之间的距离,输出结果保留1位小数。
  2. 比如,键盘输入:0 1 3 5,屏幕输出:5.0

提高题:

  1. 键盘输入小明学习的课程以及考试分数信息,信息之间采用空格分隔,每个课程一行,空格回车结束录入,示例格式如下:
  2. 数学 90
  3. 语文 95
  4. 英语 86
  5. 物理 84
  6. 生物 87
  7. 输出得分最高和最低的课程名称、考试分数,以及所有课程的平均分(保留2位小数)
  8. 格式如下:
  9. 最高分课程是语文 95,最低分课程是物理 84,平均分是88.4
  10. 答:

基础题:

  1. 从键盘输入4个数字,各数字采用空格分隔,对应为变量x0,y0,x1,y1。计算(x0y0)和(x1,y1)两点之间的距离,输出结果保留1位小数。
  2. 比如,键盘输入:0 1 3 5,屏幕输出:5.0

方法1:

  1. i = input('输入坐标').split()
  2. x1, x2, x3, x4 = eval(i[0]), eval(i[1]), eval(i[2]), eval(i[3])
  3. dis = pow((pow(x3 - x1, 2) + pow(x4 - x2, 2)), 0.5)
  4. print(dis)

方法2:

  1. variable = list(input("输入四个数字:(空格分隔)").split(' '))
  2. x0,y0,x1,y1 = variable[0],variable[1],variable[2],variable[3]
  3. distance = ((eval(x0)-eval(x1))**2 + (eval(y0)-eval(y1))**2)**0.5
  4. print("{:.1f}".format(distance))

方法3:

  1. from math import sqrt, pow
  2.  
  3. def cal_distance(x1, y1, x2, y2):
  4. return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2))
  5.  
  6. if __name__ == '__main__':
  7. x1, y1, x2, y2 = map(float, input("请输入坐标数字:").split())
  8. print(cal_distance(x1, y1, x2, y2))

方法4:

  1. a = input('input your number:').split()
  2. x0, y0, x1, y1 = int(a[0]), int(a[1]), int(a[2]), int(a[3])
  3. target = float(((y0-y1)**2+(x0-x1)**2)**0.5)
  4. print(target)

方法5:

  1. import math
  2.  
  3. s1 = input("请输入2个点坐标,用逗号分隔")
  4. lst = s1.split(',')
  5.  
  6. x0 = int(lst[0])
  7. y0 = int(lst[1])
  8. x1 = int(lst[2])
  9. y1 = int(lst[3])
  10.  
  11. a1 = int(pow((x0 - x1), 2))
  12. a2 = int(pow((y0 - y1), 2))
  13. leng = math.sqrt(a1 + a2)
  14.  
  15. print("({0},{1}),({2},{3})之间的距离为{4}" .format(x0, y0, x1, y1, leng))

提高题:

  1. 键盘输入小明学习的课程以及考试分数信息,信息之间采用空格分隔,每个课程一行,空格回车结束录入,示例格式如下:
  2. 数学 90
  3. 语文 95
  4. 英语 86
  5. 物理 84
  6. 生物 87
  7. 输出得分最高和最低的课程名称、考试分数,以及所有课程的平均分(保留2位小数)
  8. 格式如下:
  9. 最高分课程是语文 95,最低分课程是物理 84,平均分是88.4
  1. 方法1
  1. j = input('请输入课程和成绩').split()
  2. k = {}
  3. sum = 0
  4. for i in range(0, len(j), 2):
  5. k[j[i]] = eval(j[i+1])
  6. sum += eval(j[i+1])
  7. k1 = sorted(k.items(),key=lambda k : k[1])
  8. print('最高课和成绩:', k1[-1])
  9. print('最低课和成绩:', k1[0])
  10. print('均值:{:.2f}'.format(sum/(len(j)/2)))

  1. 方法2
  1. info_list = []
  2. scores, subjects = 0, 0
  3. while True:
  4. info = input("请输入小明成绩:(以空格分隔;回车结束录入)")
  5. if info == '':
  6. break
  7. else:
  8. info_list.append(info.split(' '))
  9. scores += eval(info.split(' ')[1])
  10. subjects += 1
  11. info_list.sort(key=lambda x: x[1], reverse=True)
  12. print("最高分课程是{}:{},最低分课程是{}:{},平均分是{:.1f}".format(info_list[0][0], info_list[0][1], info_list[-1][0], info_list[-1][1], scores / subjects))

  1. 方法3
  1. class Student:
  2. name = '姓名'
  3. course = 'none'
  4. course_score = -1
  5.  
  6. def theHighestScore(self, course_score_list):
  7. return max(course_score_list)
  8.  
  9. def theLowestScore(self, course_score_list):
  10. return min(course_score_list)
  11.  
  12. def theAverageScore(self, course_score_list):
  13. sum = 0
  14. for score in course_score_list:
  15. sum += score
  16.  
  17. average_score = sum / len(course_score_list)
  18. return average_score
  19.  
  20. if __name__ == '__main__':
  21. student = Student()
  22. student.name = '小明'
  23.  
  24. course_score_dict = {}
  25.  
  26. student.course = list(map(str, input("请先输入课程名:").strip().split()))
  27. student.course_score = list(map(float, input("然后请输入课程对应考试分数:").strip().split()))
  28.  
  29. course_score_dict = dict(zip(student.course, student.course_score))
  30.  
  31. print(course_score_dict)
  32. theHighestScore = student.theHighestScore(student.course_score)
  33. theLowestScore = student.theLowestScore(student.course_score)
  34.  
  35. print('最高分课程是%s %d' % (max(course_score_dict, key=course_score_dict.get), theHighestScore))
  36. print('最低分课程是%s %d' % (min(course_score_dict, key=course_score_dict.get), theLowestScore))
  37. print('平均分是', student.theAverageScore(student.course_score))

方法4:

  1. c_s_list = {} # class & score
  2. sum = 0 # 均值
  3. while True:
  4. a = input('input your class && score:')
  5.  
  6. if a == 'esc':
  7. for key, value in c_s_list.items():
  8. print(key,value)
  9. sum += int(value) # 均值
  10.  
  11. max_min = sorted(c_s_list.items(), key=lambda s: s[1])
  12.  
  13. print('\n得分最高的课程名称:{}考试分数:{}'.format(max_min[-1][0], max_min[-1][1]))
  14. print('得分最低的课程名称:{}考试分数:{}'.format(max_min[0][0], max_min[0][1]))
  15. print('均值:%.1f' % (sum/len(c_s_list)))
  16. break
  17. else:
  18. b = a.split()
  19. c_s_list[b[0]] = b[1]

Python【每日一问】35的更多相关文章

  1. [python每日一练]--0012:敏感词过滤 type2

    题目链接:https://github.com/Show-Me-the-Code/show-me-the-code代码github链接:https://github.com/wjsaya/python ...

  2. Python每日一练(1):计算文件夹内各个文章中出现次数最多的单词

    #coding:utf-8 import os,re path = 'test' files = os.listdir(path) def count_word(words): dic = {} ma ...

  3. python每日一函数 - divmod数字处理函数

    python每日一函数 - divmod数字处理函数 divmod(a,b)函数 中文说明: divmod(a,b)方法返回的是a//b(除法取整)以及a对b的余数 返回结果类型为tuple 参数: ...

  4. 每日一问:Android 消息机制,我有必要再讲一次!

    坚持原创日更,短平快的 Android 进阶系列,敬请直接在微信公众号搜索:nanchen,直接关注并设为星标,精彩不容错过. 我 17 年的 面试系列,曾写过一篇名为:Android 面试(五):探 ...

  5. 每日一问:谈谈 volatile 关键字

    这是 wanAndroid 每日一问中的一道题,下面我们来尝试解答一下. 讲讲并发专题 volatile,synchronize,CAS,happens before, lost wake up 为了 ...

  6. 每日一问:讲讲 Java 虚拟机的垃圾回收

    昨天我们用比较精简的文字讲了 Java 虚拟机结构,没看过的可以直接从这里查看: 每日一问:你了解 Java 虚拟机结构么? 今天我们必须来看看 Java 虚拟机的垃圾回收算法是怎样的.不过在开始之前 ...

  7. 每日一问:你了解 Java 虚拟机结构么?

    对于从事 C/C++ 程序员开发的小伙伴来说,在内存管理领域非常头疼,因为他们总是需要对每一个 new 操作去写配对的 delete/free 代码.而对于我们 Android 乃至 Java 程序员 ...

  8. 每日一问:LayoutParams 你知道多少?

    前面的文章中着重讲解了 View 的测量流程.其中我提到了一句非常重要的话:View 的测量匡高是由父控件的 MeasureSpec 和 View 自身的 `LayoutParams 共同决定的.我们 ...

  9. 每日一问:简述 View 的绘制流程

    Android 开发中经常需要用一些自定义 View 去满足产品和设计的脑洞,所以 View 的绘制流程至关重要.网上目前有非常多这方面的资料,但最好的方式还是直接跟着源码进行解读,每日一问系列一直追 ...

  10. python每日一练:0007题

    第 0007 题: 有个目录,里面是你自己写过的程序,统计一下你写过多少行代码.包括空行和注释,但是要分别列出来. # -*- coding:utf-8 -*- import os def count ...

随机推荐

  1. php ip伪装访问

    打算做个采集,无记录下来备用 php的curl搞定ip伪装来采集内容.以前写过一段代码采集一个数据来处理.由于数据量过大,同一ip采集.经常被限制,或者列为黑名单.   写了段代码伪装ip,原理是,客 ...

  2. [bzoj4066/2683]简单题_KD-Tree

    简单题 bzoj-4066 题目大意:n*n的棋盘,开始为均为0,支持:单点加权值,查询矩阵权值和,强制在线. 注释:$1\le n\le 5\cdot 10^5$,$1\le m \le 2\cdo ...

  3. P1464 Function 洛谷

    https://www.luogu.org/problem/show?pid=1464 题目描述 对于一个递归函数w(a,b,c) 如果a<=0 or b<=0 or c<=0就返回 ...

  4. BlockQueue中ArrayBlockingQueue和LinkedBlockingQueue比较

    LinkedBlockingQueue是BlockingQueue的一种使用Link List的实现,它对头和尾(取和添加操作)采用两把不同的锁,相对于ArrayBlockingQueue提高了吞吐量 ...

  5. [转]数据库查询 sysobjects

    sysobjects sysobjects是系统自建的表,里面存储了在数据库内创建的每个对象(约束.默认值.日志.规则.存储过程等),各在表中占一行.只有在 tempdb 内,每个临时对象才在该表中占 ...

  6. HDU 4522

    DIJK,最短路,建两个图就好了. #include <cstdlib> #include <cstdio> #include <cstring> #include ...

  7. [iOS]怎样在iOS开发中切换显示语言实现国际化

    1.在Project设置,加入中英两种语言: 2.新建Localizable.strings文件,作为多语言相应的词典,存储多种语言,点击右側Localization,勾选中英: watermark/ ...

  8. Python常用模块【sys】

    sys.argv 参数    「argv」是「argument variable」参数变量的简写形式.一般在命令行调用的时候由系统传递给程序.这个变量其实是一个List列表,argv[0] 一般是“被 ...

  9. ASP.NET MVC 认证模块报错:“System.Configuration.Provider.ProviderException: 未启用角色管理器功能“

    新建MVC4项目的时候 选 Internet 应用程序的话,出来的示例项目就自带了默认的登录认证等功能.如果选空或者基本,就没有. 如果没有,现在又想加进去,怎么办呢? 抄啊.将示例项目的代码原原本本 ...

  10. android自定义dialog中点击listview的item事件关闭dialog

    import android.app.Activity; import android.app.AlertDialog; import android.app.AlertDialog.Builder; ...