Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python questions. 1.Which expression correctly removes all empty strings from a

ID: 3938574 • Letter: P

Question

Python questions.

1.Which expression correctly removes all empty strings from a list of strings text?

[s.notempty() for s in text]

[len(s)>0 for s in text]

[s for s in text if s]

2. Variable data is a list. Which of the following code fragments produce the same value of the variable result? (Select both.)

i = 0; result = []
while i < len(data):
if data[i].foobar() == True:
print(data[i])
i += 1

[item for item in data if item.foobar()]

result = 0
for item in data:
if item.foobar() == True:
result += item

result = []
for item in data:
if item.foobar():
result.append(item)

3. Which of the following can be X in the following code fragment? (Check all that apply.)

for foo in X:
  bar(foo)

tuple()

bool()

int()

list()

str()

[s.notempty() for s in text]

[len(s)>0 for s in text]

[s for s in text if s]

2. Variable data is a list. Which of the following code fragments produce the same value of the variable result? (Select both.)

i = 0; result = []
while i < len(data):
if data[i].foobar() == True:
print(data[i])
i += 1

[item for item in data if item.foobar()]

result = 0
for item in data:
if item.foobar() == True:
result += item

result = []
for item in data:
if item.foobar():
result.append(item)

3. Which of the following can be X in the following code fragment? (Check all that apply.)

for foo in X:
  bar(foo)

tuple()

bool()

int()

list()

str()

Explanation / Answer

#include<iostream>

#include<conio.h>

using namespace std;

// Class Declaration

class prime

{

//Member Varibale Declaration

int a,k,i;

public:

prime(int x)

{

a=x;

}

// Object Creation For Class

void calculate()

{

k=1;

{

for(i=2;i<=a/2;i++)

if(a%i==0)

{

k=0;

break;

}

else

{

k=1;

}

}

}

void show()

{

if(k==1)

cout<<" "<<a<<" is Prime Number.";

else

cout<<" "<<a<<" is Not Prime Numbers.";

}

};

//Main Function

int main()

{

int a;

cout<<"Enter the Number:";

cin>>a;

// Object Creation For Class

prime obj(a);

// Call Member Functions

obj.calculate();

obj.show();

getch();

return 0;

}