你还在为考试焦头烂额?找我们就对了!
我们知道现在是考试月,你正在为了考试复习到焦头烂额。为了让更多留学生在备考与学习季更轻松,我们决定将Gold会员限时免费开放至2025年12月31日!原价£29.99每月,如今登录即享!无门槛领取。
助你高效冲刺备考!
题目
单项选择题
Question at position 7 If the missing lines are filled in correctly, the program should go through a list of emails and for each email remove the at sign (@) and all characters after it. [table] 1 emails = ['user321@gmail.com',2 'mywork@proton.me',3 'info1110@sydney.edu.au']4 5 i = 06 while i < len(emails):7 j = 08 while # ( code WILL go here ) :9 if # ( code WILL go here ) == '@':10 # ( code WILL go inside IF )11 j = j + 112 i = i + 113 14 print(emails) [/table] After execution of the code fragment, the value of emails will be:['user321', 'mywork', 'info1110']Which of the following options is the correct missing code? (Code filled in has been bolded.) Note: string[:n] returns the first n characters in string.8 while j < len(emails):9 if emails[i][j] == '@':10 emails[i] = emails[i][:j]8 while j < len(emails[i]):9 if emails[j][i] == '@': 10 emails[j] = emails[j][:i]8 while j < len(emails[i]):9 if emails[i][j] == '@':10 emails[i] = emails[i][:j]8 while i <= j:9 if emails[i][j] == '@':10 emails[i] = emails[i][:j]Clear my selection
选项
A.8 while j < len(emails):
9 if emails[i][j] == '@':
10 emails[i] = emails[i][:j]
B.8 while j < len(emails[i]):
9 if emails[j][i] == '@':
10 emails[j] = emails[j][:i]
C.8 while j < len(emails[i]):
9 if emails[i][j] == '@':
10 emails[i] = emails[i][:j]
D.8 while i <= j:
9 if emails[i][j] == '@':
10 emails[i] = emails[i][:j]
查看解析
标准答案
Please login to view
思路分析
Question recap: We’re given a Python code fragment that processes a list of emails and, for each email, removes everything from the at-sign '@' onward. The task is to pick the missing code snippet that, when filled in, results in emails being ['user321', 'mywork', 'info1110'] after execution.
Option 1: 8 while j < len(emails):
9 if emails[i][j] == '@':
10 emails[i] = emails[i][:j]
- What’s wrong here is the loop condition uses len(emails), which is the number of emails in the list, not the length of the current email string. Iterating j up to len(emails) would access invalid indices for many emails and doesn’t focus on the characters of a single email. The inner check emails[i]......Login to view full explanation登录即可查看完整答案
我们收录了全球超50000道考试原题与详细解析,现在登录,立即获得答案。
类似问题
What is the results stored in variable str?string strURL = "http://www.nyp.edu.sg";var str = str.Substring(IndexOf('.',4);
Write a generic expression using string manipulation to check if the following email has a username of more than 4 characters String user = "username"; if ( ___________________)
Write the generic expression using string manipulation to extract the month information of a date of birth (DOB) from the following string:String strDOB = "My date of birth is 15/12/2008 (DD/MM/YYYY)";String month = strDOB.Substring( ____________ ) ;
What is the correct string manipulation syntax to extract the first 2 digits of the admin number? string str = "170064B";
更多留学生实用工具
希望你的学习变得更简单
为了让更多留学生在备考与学习季更轻松,我们决定将Gold 会员限时免费开放至2025年12月31日!