First, a list of store
Plot the following two lists in memory of how to store
l1=[11,22,[333,444]]
l2=[11,22,[33,{'name':'egon','age':18}]]
Second, the interaction with the user
1, the user enters the name, age, work, hobbies, and then printed in the following format
'''------------ info of Egon -----------
Name : Egon
#Age : 22
Sex : male
Job : Teacher
------------- end -----------------
'''
name_of_user = input('请输入您的名字:')
age_of_user = input('请输入您的年龄:')
sex_of_user = input('请输入您的性别:')
job_of_user = input('请输入您的工作:')
begin = '------------ info of Egon -----------\n'
end = '------------- end -----------------\n'
output_name = 'Name:{Name}\n Age{age}\n sex:{sex}\n job:{job}\n'.format(Name=name_of_user, age=age_of_user,sex=sex_of_user, job=job_of_user)
print(begin, output_name, end)
2, the user enters the account password, the program is determined separately account and password are correct, the correct output True, False error output can be
info_user = {
'Lance1': '123',
'Lance2': '123',
'Lance3': '123',
'Lance4': '123',
'Lance5': '123',
}
user_name = input("请输入您的账号:")
user_pwd = input("请输入您的密码:")
if user_name in info_user:
if user_pwd == info_user.get(user_name):
print(True)
else:
print(False)
else:
print(False)
3, make a note of the computer in advance egon at the age of 18 years, wrote a program before age requires user input to guess the age, and the program got egon age and the age of the user input, and outputs a result of the comparison can be
age_of_egon = 18
age_of_input = input("请猜测egon的年龄并输入:")
if age_of_egon == age_of_input:
print("恭喜您,您的猜测是正确的!!")
else:
print("很遗憾,您的猜测是错误的!!")
Third, the related operator
1, taken from the database program 10000 data, intends to display the page, but a page display up to 30 data, please select the appropriate arithmetic operators, calculations show that over 30 pages of data a total of how many? Finally, a few display data?
sql_data = 10000
page = sql_data // 30
last_data = sql_data % 30
print('显示满30条数据的页面总共有{num}个\n最后一页显示{data}条数据\n'.format(num=page, data=last_data))
2, egon this year is 18 years old, please assign computing egon teacher after 3 years of age incremental
age_of_egon = 18
age_of_egon += 3
print('计算3年后egon老师的年龄是:{age}'.format(age=age_of_egon))
3, the one-time value 10 is assigned to the variable names x, y, z
x = y = z = 10
4, add the following values related to the corresponding variable name that it should, you know
dsb = "egon"
superman = "alex"
dsb, superman = superman, dsb
print(dsb, superman)
5, we just want to extract out sucker list, disposable assigned to the corresponding variable name to
names = ['alex_sb', 'wusir_sb', 'oldboy_sb', 'egon_nb', 'lxx_nb', 'tank_nb']
x, y, z, *_ = names
gather = [x, y, z]
print(gather)