samedi 27 juin 2020

I can't figure out how to stop this from being printed

First time on here and pretty much my first time coding, sorry if this doesn't fit but nothing I've tried has worked. Basically, the program is supposed to print numbers 1-100 but every time there is a multiple of 3 it prints Fizz, every 5 it prints Buzz and for both it prints FizzBuzz. At the very end of the print, it always puts 101 and I can't figure out how to stop this. The whole thing is a lot of guesswork because I don't really know what I'm doing, so help is appreciated.

answer = int(1)
limit = int(100)
three: int = (3)
five: int = (5)
while answer < 100:
    if limit >= answer:
        if answer >= three and answer >= five:
            print("FizzBuzz")
            answer = answer + 1
            three = three + 3
            five = five + 5
        if answer >= three:
            print("Fizz")
            answer = answer + 1
            three = three + 3
        if answer >= five:
            print("Buzz")
            answer = answer + 1
            five = five + 5
        if not answer >= five or answer >= three:
            print (answer)
            answer = answer + 1

This is the result:

1
2
Fizz
4
Buzz
6
Fizz
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
21
Fizz
23
Fizz
Buzz
26
Fizz
28
29
FizzBuzz
31
32
Fizz
34
Buzz
36
Fizz
38
Fizz
Buzz
41
Fizz
43
44
FizzBuzz
46
47
Fizz
49
Buzz
51
Fizz
53
Fizz
Buzz
56
Fizz
58
59
FizzBuzz
61
62
Fizz
64
Buzz
66
Fizz
68
Fizz
Buzz
71
Fizz
73
74
FizzBuzz
76
77
Fizz
79
Buzz
81
Fizz
83
Fizz
Buzz
86
Fizz
88
89
FizzBuzz
91
92
Fizz
94
Buzz
96
Fizz
98
Fizz
Buzz
101

Aucun commentaire:

Enregistrer un commentaire