老男孩python29期05作业

------------恢复内容开始------------

0、分别画出下面两个列表在内存中是如何存放的
1 l1=[11,22,[333,444]]
2 l2=[11,22,[33,{'name':'egon','age':18}]]

 

1、用户输入姓名、年龄、工作、爱好 ,然后打印成以下格式

------------ info of Egon -----------

Name  : Egon
Age : 22
Sex : male
Job : Teacher
------------- end -----------------
1 name = input('please input your name: ')
2 age = input('please input your age: ')
3 gender = input('please input your gender: ')
4 job = input('please input your job: ') 
5 print('-' * 10 + 'info of Egon' + '-' * 10 + '\nName : {}\nAge : {}\nGender : {}\nJob : {}\n'.format(name, age, gender, job)+'-' * 10 + 'end' + '-' * 10)
运行结果
please input your name: 12
please input your age: 12
please input your gender: 12
please input your job: 12
----------info of Egon----------
Name : 12
Age : 12
Gender : 12
Job : 12
----------end----------

  

2、用户输入账号密码,程序分别单独判断账号与密码是否正确,正确输出True,错误输出False即可

1 user1 = 'ss'
2 password1 = '123'
3 username = input('please input your username: ')
4 password = input('please input your password: ')
5 print(f'用户名判断结果为{username == user1}')
6 print(f'密码判断结果为{password == password1}')
运行结果
please input your username: ss
please input your password: 123
用户名判断结果为True
密码判断结果为True


3、让计算机提前记下egon的年龄为18岁,写一个猜年龄的程序,要求用户输入所猜的年龄,然后程序拿到用户输入的年龄与egon的年龄比较,输出比较结果即可
 1 age1 = '18'
 2 while 1:
 3     age = input('please guess the age :')
 4     if age == age1 :
 5         print('you are right !')
 6         break
 7     elif age > age1 :
 8         print('the age you guess is too large')
 9     else :
10         print('the age you guees is too small')
运行结果:
please guess the age :17
the age you guees is too small
please guess the age :19
the age you guess is too large
please guess the age :18
you are right !

 

4、程序从数据库中取出来10000条数据,打算显示到页面中, 但一个页面最多显示30条数据,请选取合适的算数运算符,计算显示满30条数据的页面总共有多少个?最后一页显示几条数据?

1 pages = 10000 // 30
2 data_number = 10000 % 30
3 print(f'显示满的页数为{pages},最后一页显示{data_number}条数据')

运行结果

显示满的页数为333,最后一页显示10条数据

 

5、egon今年为18岁,请用增量赋值计算3年后egon老师的年龄

 

1 age = 18
2 print(f'现在年龄为{age}')
3 age += 3
4 print(f'3年后年龄为{age}')

运行结果

1 现在年龄为18
2 3年后年龄为21

 

6、将值10一次性赋值给变量名x、y、z
1 z = y = x = 10
2 print(x,y,z)
运行结果
10 10 10

7、请将下面的值关联到它应该对应的变量名上,你懂的
1 dsb = "egon"
2 superman = "alex"
3 dsb, superman = superman, dsb
4 print(dsb,superman)

运行结果

1 alex egon

 

8、我们只需要将列表中的傻逼解压出来,一次性赋值给对应的变量名即可
names=['alex_sb','wusir_sb','oldboy_sb','egon_nb','lxx_nb','tank_nb']
x,y,z,*_=names
print(x,y,z,_)

运行结果


alex_sb wusir_sb oldboy_sb ['egon_nb', 'lxx_nb', 'tank_nb']

 

 
posted @ 2021-10-15 11:13  LastNever  阅读(138)  评论(0)    收藏  举报