1. 写一段程序实现以下功能
读入用户输入的姓名,打印"你好!xxx",要求输出的字符串占20个宽度,不够补*,居中对齐
n = input("请输入你的姓名:")
m = "你好!,"
y = m + n
print("{:*^20}".format(y))
2.人类的思维习惯于"四舍五入",请问int在做强转的时候会四舍五入吗?如果不会,想办法是的其进行四舍五入
不会
x=float(input("请输入一个数"))
m=int(x)
n=x%m
if n>=0.5:
print(int(x)+1)
else:
print(int(x))
3.python中的变量名字可以是中文吗?请尝试
可以是中文
姓名="name" 年龄=25 print("姓名是{},年龄是{}".format(姓名, 年龄))
姓名是name,年龄是25
4.下列语句哪个是非法的(b)
a. x = y = z = 1 b. x=(y=z+1) c. x, y = y, x d. x += y
5.以下各个语句的值
a. 1 and 0 or 2 and 3 or 3 and 0
3
b. 100 % 2 and 5 or 3 and 5 < 100
True
c. 5 is 6 or 3 and 0 and 3
0
通过本次课我学到了python的历史背景和基本数据类型中的布尔类型(True,False)和数字类型(int,float),了解到运算符的优先级,学到一些函数使用方法(如:int() ,pow() ,divmod(),abs()),字符串的定义函数str和字符串的索引和切片,字符串中会用到的运算符(+ / *n / in / not in)和一些函数(len()/max() / min() / .index() / .count()/.format),还有读入和输出。