Exam PCAP All QuestionsBrowse all questions from this exam
Question 44

How many stars (*) does the snippet print?

    Correct Answer: A

    The code is erroneous because the subtraction operator '-' is not supported for strings in Python. Only concatenation '+' and repetition '*' are allowed for strings. Therefore, attempting to use the '-' operator with strings will result in a TypeError.

Discussion
pypaulOption: A

A is answers. The snippet wiill generate a TypeError

smarty_arseOption: A

Correct. TypeError will be thrown

macxszOption: A

A. the code is erroneous

seaverickOption: A

s='*****' s= s - s[2] #TypeError: unsupported operand type(s) for -: 'str' and 'str' print(s) #For strings, only + ( concatenate ) and * (multiply) is allowed. TypeError will be returned #TypeError: unsupported operand type(s) for -: 'str' and 'str' #Ans: the code is erroneous

ArulkumarOption: A

For strings, only + ( concatenate ) and * (multiply) is allowed. TypeError will be returned Ans: A

SuvabrataOption: A

A is correct. strings support concatenation. '-' is not supported in strings

666_mOption: A

A. the code is erroneous is correct

Noarmy315Option: A

-(minus) is not supported b/n 'str' and 'str', if +(plus) then it works, ex. s=s+s[2] then '******' six stars