Skip to content

Instantly share code, notes, and snippets.

@bugkiller78
Created October 18, 2020 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bugkiller78/71523a6ffe7321bcb8e902444502217d to your computer and use it in GitHub Desktop.
Save bugkiller78/71523a6ffe7321bcb8e902444502217d to your computer and use it in GitHub Desktop.
SmartNinja_DN2_2
#DN2.2 FIZZBUZZ
print('Welcome to FIZZ AND BUZZ program')
number = int(input( 'Please enter your desired number between 1 and 100:'))
for x in range(1, number + 1): #določi število ponovitev loopa
if x % 3 == 0: # Če je številka deljiva z celim številom dobimo vrednost 0 , če ni pa vrednost 1
print('FIZZ')
elif x % 5 == 0:
print('BUZZ')
elif x % 3 == 0 and x % 5 == 0:
print('FIZZBUZZ')
else:
print(x)
print('')
print('GAME OVER')
Copy link

ghost commented Oct 21, 2020

Manjka ti del ki omeji vnos stevila med 1 in 100.
Eno izmed moznih resitev implementacije ti posiljam spodaj:

while True:
    num = int(input('Vnesi poljubno število med 1 in 100: '))

    if num > 100 or num <1:
        print("Vnešena številka je neveljavna. Poskusite znova.")
    else:
        for x in range(1, num + 1):  # Za range od 1 do poljubnega števila (povečano za 1,ker Python šteje od 0)

            if x % 3 == 0 and x % 5 == 0:  # če je število deljivo s 3 in 5
                print("fizzbuzz")
            elif x % 3 == 0:
                print("bizz")
            elif x % 5 == 0:
                print("buzz")
            else:
                print(x)
        break

V tej kodi mora uporabnik vnasati stevilo tako dolgo dokler ga ne vnese med 1 in 100, ko pa mu program izpise pravilno, se hkrati tudi zakljuci.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment