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

IN PYTHON Question 1: Write a program that uses a while loop to calculate and pr

ID: 3700982 • Letter: I

Question

IN PYTHON Question 1: Write a program that uses a while loop to calculate and print the multiples of 3 from 3 to 21. Your program should print each number on a separate line. Sample Run 3 6 9 12 15 18 21

Question 2: Write a program that inputs numbers and keeps a running sum. When the sum is greater than 100, output the sum as well as the count of how many numbers were entered. Sample Run Enter a number: 1 Enter a number: 41 Enter a number: 36 Enter a number: 25 Sum: 103 Numbers Entered: 4

Question 3: Write a loop that continually asks the user what pets the user has, until the user enters "rock", in which case the loop ends. It should acknowledge the user in the following format. For the first pet it should say "You have a dog with a total of 1 pet(s)" if they enter dog, and so on. Sample Run: User enters: lemur parrot cat rock Outputs: You have a lemur with a total of 1 pet(s) You have a parrot with a total of 2 pet(s) You have a cat with a total of 3 pet(s)

Explanation / Answer

1)

// A Simple C++ program to find count of all

// numbers that multiples

#include<iostream>

using namespace std;

// Returns count of all numbers smaller than

// or equal to n and multples of 3 or 7 or both

void countMultiples(int x ,int y)

{

int res = 0;

for (int i=x; i<=y; i++)

if (i%3==0 ){

  

cout<<i;

cout << " ";

}

}

// Driver code

int main()

{

countMultiples(3,21);

}

2)

// A Simple C++ program to find count of all

// numbers that multiples

#include<iostream>

using namespace std;

// Returns count of all numbers smaller than

// or equal to n and multples of 3 or 7 or both

// Driver code

int main()

{

int number,sum=0, count=0;

cin >> number;

while(sum<=100){

cin >> number;

sum=sum+number;

count++;

}

cout<<sum<<count;

}