Day2--课后作业
1.写代码获取数字1234中的十位上和百位上的数字
方法一:
number =1234
a,b,c,d= str(number)
print(b,c)
方法二:
number =1234
num1=(number-1000)//100
print(num1)
num2=(number-1200)//10
print(num2)
2.如果变量n的值是6784, 以下表达式的结果是多少?
结果为:6.784, 7.84, 7 ,7
number = 6784
num1=number / 1000 % 100
num2=number % 1000 / 100
num3=number // 100 % 10
num4=number // 10 % 100 // 10
print(num1,num2,num3,num4)
3.表达式 10 / 4 + 23 // 4 * 2 - 30 的结果是多少?
结果为:-17.5
number =10 / 4 + 23 // 4 * 2 - 30
print(number)
4.写出下面每一行中n3的结果:
n1 = 4; n2 = 5
n3 = n1 >n2
n3 = n1<n2
n3 = n1==4
n3 = n1!=4
n3 = n1 == 1+3
结果为:
False
True
True
False
True
n1 = 4; n2 = 5
n3 = n1 >n2
print(n3)
n3 = n1<n2
print(n3)
n3 = n1==4
print(n3)
n3 = n1!=4
print(n3)
n3 = n1 == 1+3
print(n3)
5.写出以下代码执行完成后,num的结果
num = 10
num /= 2
num += 10 * 10 / 4 + 23*2
结果为:48.0
num = 10
num /= 2
num += 10 * 10 / 4 + 2*3**2
print(num)
6.下面定义变量正确的是()
a. a = b = c = 10
b. a, c = 10
c. in = 20
d. num = 10; t = 20
结果为:a 、d
b选项语法错误,c选项误用关键字