winnywang0315 2023-11-28 02:11 采纳率: 60%
浏览 41
已结题

Python, Linux and SQL

十分抱歉,由于网站上传照片需要压缩,没想到压缩成了碎碎,让大家难以分辨。这两天忙着去上课啦,回来一看信息炸锅~现重新整理文本形式,之后再追加的酬金,谢谢大家啦!请大家点击Google doc,please,因为还是有图片,无法纯文字。

  1. The purpose of this code is to print "user flagged" if the username is "jhill", and otherwise to print "user okay". Run this code, analyze its output, and debug it. (If you want to undo your changes to the code, you can click the Reset button.)

How can you fix this error?
a. Use the != operator instead of the == operator in the conditional header.
b. Add an else statement before the line that prints "user okay".
c. Remove indentation from the line that prints "user okay" so that it is not part of the conditional.
d. Call check_user() before the function definition.

  1. You did not assign a value to a variable before using it in a conditional statement. What type of error is this?
    a. Syntax error
    b. Exception
    c. Index out of bounds
    d. Logic error

  2. When debugging code, what are effective ways to determine which sections of code are working properly? Select all that apply.
    o Use a debugger
    o Add comments in the code
    o Add print statements
    o Delete blank lines from the code

  1. You want to check for unusual login activity. Specifically, you want to read a log file that contains information on each login attempt, including whether it failed or was successful. You should then parse the data into a logins list, and then you should separate all failed log entries into a separate failed_logins list. If you want to automate this through Python, what would be part of your code? Select three answers.
    o A for loop to iterate through all items in the logins list
    o An if statement to check if a login attempt failed
    o A counter variable to keep track of the number of failed logins
    o A split() function to split the login information into a list

关于Python, Linux and SQL错误习题,请大家帮助解答!感谢!

  • 写回答

23条回答

  • 专家-赤兔[在线] 优质创作者: 编程框架技术领域 2023-11-28 02:11
    关注
    获得1.00元问题酬金

    引自强大而免费的微信公众号:皆我知道

    1.To fix the error in the code, option b. Add an else statement before the line that prints "user okay" would be the correct solution. This would ensure that if the username is not "jhill", the program will execute the else block and print "user okay".

    2.The error of using a variable before assigning a value to it in a conditional statement is a. Syntax error. This is because it violates the syntax rules of the programming language.

    3.Effective ways to determine which sections of code are working properly when debugging include:

    • Using a debugger to step through the code and track the flow of execution.
    • Adding comments in the code to explain the purpose and logic of different sections.
    • Adding print statements to display the values of variables or the execution flow at specific points in the code.

    Deleting blank lines from the code would not be an effective way to determine which sections of code are working properly.

    4.To automate the process of reading a log file, parsing the data into a logins list, and separating failed log entries into a separate failed_logins list, the following would be part of the code:

    • A for loop to iterate through all items in the logins list.
    • An if statement to check if a login attempt failed.
    • A counter variable to keep track of the number of failed logins.
    • A split() function to split the login information into a list.
    评论 编辑记录

报告相同问题?

问题事件

  • 系统已结题 12月6日
  • 修改了问题 11月29日
  • 创建了问题 11月28日