vendredi 1 novembre 2019

Program not printing correct output in specific cases

here is my code:

def bizzBuzzAnalysis(n):
    n = int(input())
    bizz = 0
    buzz = 0
    if(n%7==0):
        print(n, "is divisible by 7. Add a bizz!")
        bizz+=1

    if(n%9==0):
        print(n, "is divisible by 9. Add a buzz!")
        buzz+=1

    r = str(n)
    for i in range(len(r)):
        if r[i] == "7":
            print("Digit is 7, add a bizz!")
            bizz+=1
        if r[i] == "9":
            print("Digit is 9, add a buzz!")
            buzz+=1
    if(bizz==0 & buzz == 0):
        print(r)
    else:
        print(("Bizz! " * bizz) + ("Buzz! " *buzz))


# input and function test
n = 0
bizzBuzzAnalysis(n)

With an input of 99, the program will still print that the number is divisible by and contains the number 9. However, it will only print the number instead of the phrases it should be printing. It seems to be the case for most numbers that contain a 9. Is there something wrong with my if statements?

Aucun commentaire:

Enregistrer un commentaire