35 lines
1.5 KiB
Python
35 lines
1.5 KiB
Python
# question 5:
|
|
# The statement print("\007") outputs an ASCII escape sequence \007, which represents the Bell control character. The reason why print("\007")
|
|
# produces a sound or visual alert is that when the string "\007" is printed, it is interpreted by the terminal or system as a signal to generate
|
|
# an audible or visual alert, as defined by the specific implementation.
|
|
|
|
# question 6:
|
|
# The code print("abcdefg\rhijklmnop") will output "hijklmnopg"
|
|
# In Python, the '\r' character is a carriage return character, which instructs the console or terminal to move the cursor back to the beginning
|
|
# of the current line, without advancing to the next line. This means that anything printed after the '\r' will overwrite whatever was printed earlier
|
|
# on the same line.
|
|
|
|
# question 7:
|
|
# In this case, the carriage return character \r is treated as a regular character within the response content. It does not have the same effect as
|
|
# in the previous example where it was used in a print statement.
|
|
|
|
# qustion 8:
|
|
# If a hacker attacks a credit card system. When the customer came to buy a can of Coke, he paid 2 knives to the store, but the display in the
|
|
# background was "2/r500".
|
|
|
|
# question 9:
|
|
def validate(input_string):
|
|
if "\r" in input_string:
|
|
raise ValueError("Crime detected!")
|
|
try:
|
|
validate("abcdefg")
|
|
print("✅ test1 pass!")
|
|
except:
|
|
print("❌ test1 fail!")
|
|
|
|
try:
|
|
validate("abcdefg\rhijklmnop")
|
|
print("❌ test2 fail!")
|
|
except ValueError as err:
|
|
print("✅ test2 pass!")
|