1. Briefly describe the difference between compiled and interpreted languages, and list which languages you know are compiled and which are interpreted
Compiled type: requires a compiler, which is equivalent to first translating and then calling out, fast execution, slow debugging, such as C language Interpretation type: An interpreter is required, which is equivalent to calling out while translating, the execution is slow, and the debugging is as fast as python
2. There are two ways to execute python scripts (there are three in total)
Interactive interpreter
:
Python scripts
can be executed on the command line by introducing an interpreter in the application of
. Check if the script has executable permission.
Integrated Development Environment: What are pycharm
3.python single-line comments and multi-line comments used for?
Single-line comments use '#',
multi-line comments use '''
4. What are the Boolean values?
True and False
None, 0, empty (empty string, empty dictionary, empty list) boolean value is False
and the rest are all True
5. What are the precautions for declaring variables?
Cannot use keywords as variables .
Cannot start with numbers . Case-
sensitive
naming. Except for underscores, other symbols cannot be used
. 6.
i. Implement user input of user name and password. success, no failure
name1 = input("please input name:")
password1 = input("please input password")
if name1 == "seven" and int(password1) == 123:
print("login successful")
break
else:
print("login failed")
ii. Implement user input of user name and password, when the user name is seven and the password is At 123, it shows that the login is successful, otherwise the login fails. When it fails, it is allowed to enter three times
count = 0
while count < 3:
name1 = input("please input name:")
password1 = input("please input password")
if name1 == "seven" and int(password1) == 123:
print("Login successful")
break
else:
print(" Login failed")
count += 1
iii. Implement the user input username and password, when the username is seven or alex and the password is 123, the login is successful, otherwise the login fails, and it is allowed to repeat three times
count = 0
user = ["seven","alex"]
while count < 3: name1 = input("please input name:" password1 = input("please input password") if name1 in user and int(password1) == 123: print(" Login successful" break else:
print("Login failed")
count += 1
7.
i. Use while loop to achieve the sum of output 2-3+4-5+6....+100
i = 2
k = 0
z = 0
while i < 101 :
i += 1
if i % 2 == 0:
k = k + i
elif i % 2 != 0:
z = z - i
else:
pass
print(k+z)
ii. Use a while loop to output 1, 2 , 3, 4, 5, 7, 8, 9, 11, 12
i = 0
while i < 13:
i +=1
if i == 5 or i == 9:
print(i)
i += 2
print(i )
8. Assuming that the one-year fixed interest rate is 3.25%, how many years will it take to calculate the one-year fixed deposit of RMB 10,000, which can double the principal and interest?
all = (10000.0/100)*3.25 + 10000
year = 1
while True:
year += 1
k = all*3.25 + all
if k/10000 == 2:
print(year)
break