M Inbox 2022 jeffrey dup x saka ieuRI cso 110 spri x e lab21

M Inbox (2022) jeffrey dup. x saka ieuRI: cso 110 spri x e lab2-15-modified x Las Vegas odds Sports Sc x tr Froo Parlay Calouator and. x Problemloading pago x d-lab2- https sakai. item/11693719/group/e3dbb580-16f5-49of affo-88196032a87c/Labs/Lab 2-program Python 9 16 ylab2-f16pdf a tint 4 of PART 3: (CHALLENGED SUM OF MULTIPLES If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3,5, 6 and 9. The sum of these multiples is 23. Write a Python program that will compute the sum of all the multiples of 3 or 5 below a given number (entered by the user Instructor Initials: PART 4: (CHALLENGE) GUESSING NUMBER GAME Write an algorithm to create a Guess the Number game: The program should get a random number and then ask the user to guess the number and see how many guesses it takes. Each time the user guesses, the program should tell the user ifthe number is correct, or if it is higher than the user\'s guess, or lower than the user\'s guess. Have the program loop until the user guesses correctly. Print the number to guesses the user took to get the right number Hint: Start with the code from the lecture video for this week (find it on the sample code page of the Sakai web site). Instructor Initials:

Solution

SUM OF MULTIPLES:

#!/usr/bin/env python
import re

number = input(\"Enter Number\");
number = int(number) #else number will be considered as string
sum = 0;
for num in range(3,number): #loop from 3 to number because smallest number divisible by 3 or 5 is 3
   if (num % 3 == 0): #check if number is divisible by 3
       sum = sum + num;
   elif (num % 5 == 0): #check if number is divisible by 5
       sum = sum + num;
print (sum);

-------------------------------------------------------------------------------------------------------------------------------------------------------------------

GUESSING NUMBER GAME:

#!/usr/bin/env python
import random
# library to read random number


number = random.randint(1,100) #read a random integer between range 1 to 100
print(number) #this line is optional. prints the random integer
userInput = input(\"enter user number: \"); #read the user input
userInput = int(userInput); #convert to integer
count = 0; #count variable is used to keep the count of guess
while number != userInput: #loop untill guess is correct
   if number > userInput:
       print(\"number is higher than userInput\");
   elif number < userInput :
       print(\"number is lower than userInput\");
   count = count +1;
   userInput = input(\"enter user number: \"); #read user input
   userInput = int(userInput);
print(\"number guessed is correct\"); #print count and message when the guess is correct
print(\"number of guesses is \");
print(count);

 M Inbox (2022) jeffrey dup. x saka ieuRI: cso 110 spri x e lab2-15-modified x Las Vegas odds Sports Sc x tr Froo Parlay Calouator and. x Problemloading pago x

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site