Python Practice - Interview Question - Fizz Buzz | Mosh

preview_player
Показать описание
Fizz buzz is a popular Python interview question. Watch this video and practice Python.

Python Exercises for Beginners:

Python Cheat Sheet:

Want to learn more from me? Check out my blog and courses:

Рекомендации по теме
Комментарии
Автор

In 20+ years professional programming, in countless permanent and contract roles, I have never once seen "fizz buzz" come up as part of the recruitment process, whether I was the candidate or the interviewer.

fdfsdfsvsfgsg
Автор

conditions = {
3 : "Fizz",
5 : "Buzz",
2 : "Tuzz"
}

for i in range(0, 101):
output = ''
for condition_int in conditions:
if i % condition_int == 0:
output = output + conditions[condition_int]
if len(output) == 0:
output = i
print(output)

zackydev
Автор

Hey Mosh, pls am a 14yrs old boy from Nigeria I need to learn python programming language. i need to develop my family and my people.

freemancharles
Автор

Hey Mosh, how are you doing? I have a question for you... Do you still program in C# as your primary language or are you becoming a python programmer and getting away from C#? I am a C# programmer and I am interested on learning other languages too, but I want to know if you keep investing your time in C# or do you think worth investing in a new language like javascript or python, since I respect very much your opinion...

Автор

I don't like how you use multiple if it just looks off from how I learned from other courses, but if it works, it works!

Here's mine that takes a user input so I don't have to go into the code and delete and replace.

user = int(input('Please enter a numeric value:'))

def fizz_buzz(user):
if (user % 3 == 0) and (user % 5 == 0):
return 'Fizz AND BUZZ'
elif user % 3 == 0:
return "Fizz"
elif user % 5 == 0:
return 'Buzz'
else:
return 'Neither Fizz or Buzz'


print('Your answer to your input is: ')
print(fizz_buzz(user))

NobleAbsinthe
Автор

Hey bud, thank you so much for your vids, really helpful. And please, more like this!

enriquevanegas
Автор

This video was "Beautifull"!

VaporCode
Автор

This is really an interview question? That was super easy. Thanks for your videos Mosh!

kingdavey
Автор

I try to avoid having multiple return statements if possible. This is my solution :)

def fizz_buzz(input):
output = ""
if input % 3 == 0:
output = "Fizz"
if input % 5 == 0:
output += "Buzz"

return output if output else input

Torsan
Автор

You are great sir.lots of love for u.i love all your classes

alimran
Автор

Hi Mosh please make tutorial on spring boot and especially spring security .It will be very useful for lots of people, especially of you are doing :)

prashanttiwari
Автор

Another approach:


def fizz_buzz(input):
result = ""
if input % 3 == 0:
result += "Fizz"
if input % 5 == 0:
result += "Buzz"
if result == "":
result = str(input)
return result

thanoslampropoulos
Автор

Sir... Make new python interview questions videos

shahzan
Автор

Good explanation, keep posting videos like this?

aravind.a
Автор

Syntax :

def fizz_buzz(num):
if (num % 3) == 0 and (num % 5) == 0:
print("FizzBuzz")
elif (num % 3) == 0:
print ("Fizz")
elif (num % 5) == 0:
print("Buzz")
else:
print(num)

matankkanu
Автор

+Programming with Mosh
That's not an issue here, because you *return* a value when a condition evaluates to True, thus ending the evaluation, but otherwise, I think sequences of "if" statements can be pretty dangerous (anyone can try "print()" instead of "return" and check what happens with 15... Plus, if you don't return, every if statement will be evaluated, as opposed to what happens with "elif". Lastly, I find "if, elif(s), else" more readable and they clearly show that only *one* of the code segments will execute.

meatyout
Автор

2:10 this solution would return Buzz for any number passed other than 3.

gabehcuodsuoitneterp
Автор

I used the else block explicit to show the user that there is one special case. We have enough horizontal space :-)

deadeyea
Автор

h!! sir, could you tell me which theme you are using in vs code thanks

manvimittal
Автор

In which editor you edit the video?awesome animation and sound effect.
Totally cool.

rawaldhruv