Random lessons in programming: FizzBuzz

As a test of my extremely beginner skills in Python my husband decided to challenge me to do the FizzBuzz “task(?)”.

Here goes my solution (I did it considering someone would be inputing numbers and I tested it independently).

import sys

def FIZZBUZZprob(number):
    if number %3 == 0 and number %5 == 0:
        print("Number %s is FIZZBUZZ. You RULE!" % number)
    elif number %3 == 0:
        print("Number %s is FIZZ. Bah." % number)
    elif number %5 == 0:
        print("Number %s is BUZZ. Meh." % number)
    else:
        print("You chose %s. You Sir, Fail. Greatly." % number)

for guess in range(0,10):
    print("What is your number?")
    guess = int(sys.stdin.readline())
    FIZZBUZZprob(guess)
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s