【Python for Everybody】quiz, assignment, exercise知识点

COUNT(*)表示ItcountstherowsinthetableUsers。只能由字母或下划线开头,并只能由字母、数字、下划线(underscore)组成。
摘要由CSDN通过智能技术生成
  • int()取整是只取整数,而不是四舍五入

What will be the value of x when the following statement is executed:

x = int(98.6)
-->>98
  • 变量名命名不能以数字开头,只能是字母或下划线

Which of the following is a bad Python variable name?
Spam
SPAM23
_spam
23spam (×)
只能由字母或下划线开头,并只能由字母、数字、下划线(underscore)组成
不能由数字开头

  • print(‘’, x)字符串和变量一起输出时候中间会自动有一个空格
name = input("Enter your name")
print("Hello", name)
-->>Hello Sarah
  • 乘法运算忘记加*
#错误
    pay = 40*r+(h-40)(r*1.5)
#正确
    pay = 40*r+(h-40)*(r*1.5)
  • time-and-a-half 表示按照正常工资的1.5倍支付
  • .format()函数
print("Maximum is {}\nMinimum is {}".format(largest, smallest))
'''
-->> 
Maximum is 10
Minimum is 2
'''
  • .isdigit()函数
#该代码中没有使用try和except检查错误,在检验输入是否为数字的时候用到了isdigit()函数。
count = 0
total = 0
while True:
    shuru = input('Enter a number: ')
    if shuru.isdigit():
        count = count + 1
        total = total + int(shuru)
        continue
    if shuru == 'done':
        break   
    else:
        print("Invalid input")
print('Done!')
print("num: ", count)
print("sum: ", total
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值