Using python!!! could you help me solve the problem 3 and give the comments and
ID: 3711184 • Letter: U
Question
Using python!!! could you help me solve the problem 3 and give the comments and algorithm( the way of comments and algorithm show in the picture below)?
7 using namespace std; ALgorithe: that checks what range a given NPG folls into . 1. Take the mpg value passed to the function. 11 12 13 14 15 16 Comments (10 points) 2 Check f tt is greater than se If yes, then print "Nice Job . If not, then check f t ts greater than 25 Alorithm If yes, then print "Not great, but oay 4. If not, then print "So bad, so very, very bad (10 points) Input parometers: iles per gollon (Float type 18Output:dfferent string bosed on three cotegortes of G:50, 25-49, and Less than 25 Returns: nothing 21 23 void checkPG(Float mpg) 50) check f the Input volue ts greater than 5e 25 26 27 28 29 30 31 32 cout ee "Nice job e endl; 7 output message lse if(ng25) 7/ff not, check f is greater than 25 coutExplanation / Answer
""" Algorithm: Prints Message based on iteration i 1. Take value n passed to the function 2. Iterate from 0 to n (inclusive) 3. For Each iteration i 4. if i is divisible by both 3 and 5, print FizzBuzz 5. if i is only divisible by 3, print Fizz 6. if i is only divisible by 5, print Buzz 7. else print the number """ def fizz_buzz(n): for i in range(n + 1): # iterate from 0 to n inclusive if i == 0: # if i is 0, print 0 print(0) elif i % 3 == 0 and i % 5 == 0: # if i is divisible by both 3 and 5 print FizzBuzz print('FizzBuzz') elif i % 3 == 0: # if i is only divisible by 3, print Fizz print('Fizz') elif i % 5 == 0: # if i is only divisible by 5, print Buzz print('Buzz') else: # else print number itself print(i)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.