zoukankan      html  css  js  c++  java
  • 小甲鱼Python第七讲课后习题

    0.if not(money < 100):上边这行代码相当于?

    if money>=100

    1.assert 的作用是什么?

    assert “断言”,当这个关键字后边的条件为假的时候,程序自动崩溃并抛出 AssertionReeor

    2.假设有x=1,y=2,z=3,请问如何快速将三个变量的值相互交换?

    x,y,z=1,2,3

    x,y,z=z,y,x

    print(x,y,z)

    3.你听说过成员资格运算符吗?

    Python 有一个成员资格运算符:in,用于检查一个值是否在序列中,如果在序列中返回True,否则返回False
    >>> name ="小甲鱼"
    >>> '鱼' in name
    True
    >>> '哈哈' in name
    False

    动手

    0.按照100分制,90分以上成绩为A,80到90为B,70到80为C,60到70为D,其余为不及格

    注意:三元操作符   small = x if x < y else y

    自己写的代码还是很Low

    while True:
    temp=input("chengji")
    while temp.isspace() or not temp.isdigit():
    temp =input("chongxinshuruchengji")
    a=int(temp)
    if a>=90:
    print('A')
    elif a>=80 and a<90:
    print('B')
    elif a>=70 and a<80:
    print('C')
    elif a>=60 and a<70:
    print('D')
    else:
    print('不及格')
    附加:
    temp = input("请输入分数:")
    score = int(temp)
    while score > 100 or score <0:
        temp = input("输入错误,请重新输入")
        score = int(temp)
    if 90 <= score <= 100:
        print("A")
    elif 80 <= score < 90:
        print("B")
    elif 70 <= score < 80:
        print("C")
    elif 60 <= score <70:
        print("D")
    else:
        print("不及格")

    1.转换成三元操作符

    x,y,z =6,5,4

    if x<y:

      small=x

      if z<small:

        small=z

    elif y<z:

      small=y

    else:

      small=z

    small = x if x<( y if y<z else z) else ( y if y<z else z)

  • 相关阅读:
    hdu 4027 Can you answer these queries?
    hdu 4041 Eliminate Witches!
    hdu 4036 Rolling Hongshu
    pku 2828 Buy Tickets
    hdu 4016 Magic Bitwise And Operation
    pku2886 Who Gets the Most Candies?(线段树+反素数打表)
    hdu 4039 The Social Network
    hdu 4023 Game
    苹果官方指南:Cocoa框架(2)(非原创)
    cocos2d 中 CCNode and CCAction
  • 原文地址:https://www.cnblogs.com/jieperhaps/p/9003234.html
Copyright © 2011-2022 走看看