zoukankan      html  css  js  c++  java
  • 练习1

    【需求】输入一个分数。分数在0-100之间。90以上是A,80以上是B,70以上是C,60以上是D,60以下是E。

    方法1、

    score = int(input("请输入分数:"))
    grad = ""
    if score >100 or score <0:
        score = int(input('请输入分数(0-100):'))
    elif score >= 90:
        grad = 'A'
    elif score >= 80:
        grad = "B"
    elif score >= 70:
        grad = "C"
    elif score >= 60:
        grad = "D"
    else:
        grad = "E"
    print("成绩是{0},等级为{1}".format(score,grad))

    方法2:

    score = int(input("请输入分数:"))
    grade = "ABCDE"
    num = 0
    if score >100 or score < 0:
        score = int(input("请输入分数(0-100):"))
    else:
        num = score // 10
        if num < 6:
            num = 5
        print('分数为{0},等级为{1}'.format(score,grade[9-num]))

    【需求】用列表和字典存储下表信息,并打印出表中工资高于30000的数据。

    d1 = dict(name='勒布朗',age=35,salary=35000,city="洛杉矶")
    d2 = dict(name='凯文',age=30,salary=30000,city="布鲁克林")
    d3 = dict(name='巴特勒',age=32,salary=20000,city="迈阿密")
    d4 = dict(name='欧文',age=28,salary=18000,city="鲁克林")
    d5 = dict(name='戴维斯',age=29,salary=33000,city="洛杉矶")
    
    l = [d1,d2,d3,d4,d5]
    for i in l:
        if i.get('salary')>30000:
            print(i)
  • 相关阅读:
    算法题-数组算法题
    Linux-shell脚本的调试和追踪
    Linux-循环loop
    Linux-条件判断式
    Linux-第一行#!/bin/bash的含义
    Linux-排序命令:sort、wc、uniq
    Linux-选取命令:cut grep
    Linux-shell变量
    Linux-重定向、追加、tee
    Linux三剑客-sed编辑文本
  • 原文地址:https://www.cnblogs.com/ljwpython/p/14632048.html
Copyright © 2011-2022 走看看