+ 11

Somebody help me check this code. The output still include the numbers represented by the strings.

I don't want numbers like 3, 5, 6, 9, 12, 15 etc to be seen in the output. I want them represented by the strings. Thank you all https://code.sololearn.com/c446kzFZS83q/?ref=app

20th Sep 2019, 1:23 PM
Surveyor
Surveyor - avatar
10 Antworten
+ 4
I see you have attached the code link. Thanks for understanding 👍 (Edit) It seems you're doing a Fizzbuzz variant. I made a little change here, tested and runs in Playground. Talk to me if there's any doubt okay. Felix, Alabi = "Felix", "Alabi" for a in range(1, 51): FD3, FD5 = (a % 3 == 0), (a % 5 == 0) if FD3 and FD5: print(Felix, Alabi) else: if FD3: print(Felix) elif FD5: print(Alabi) else: print(a)
21st Sep 2019, 2:36 AM
Ipang
+ 9
Ipang How can i attach the code link in the description?
20th Sep 2019, 7:57 PM
Surveyor
Surveyor - avatar
+ 8
Ipang thanks for the help. I really want to learn from the solution u provided. Does it mean i need to handle situation with more conditions before the ones with less condition? Looking at how u solved it. I discovered u dealt with the one with 2 conditions before ones with 1 condition. Please corroborate. Thanks.
23rd Sep 2019, 8:13 AM
Surveyor
Surveyor - avatar
+ 8
Ipang Thank you once again
23rd Sep 2019, 9:35 AM
Surveyor
Surveyor - avatar
+ 8
Clémentine 🍊 Thanks so much 👍🏽
23rd Sep 2019, 3:37 PM
Surveyor
Surveyor - avatar
+ 5
Actually, it has to do with the way that the "elif" (="else if") condition works. First, the computer will read the "if" condition : - if it evaluates to False, the computer will examine the next condition starting with "elif" - but if it evaluates to True, the computer does not even read the "elif" instructions, which mean "otherwise, if...". It will just jump to the next block of code or to the next iteration of the loop. In your original code, the third instruction could never be read, since it was a combination of the first and second conditions. If a number could be divided by 3 and 5, the computer always stopped at the first condition : the number could be divided by 3, so it printed "Felix" and moved on to the next number. This exercise is actually meant to help you understand how the "if"/"elif" statement works : the order is extremely important and it is the first thing that you should decide before writing the code.
23rd Sep 2019, 9:58 AM
Clémentine 🍊
Clémentine 🍊 - avatar
+ 3
You're welcome ! I hope it helps (:
23rd Sep 2019, 9:54 PM
Clémentine 🍊
Clémentine 🍊 - avatar
+ 1
Please attach the code link in Description section. I think you forgot to do it, but in your question said "Somebody help me check this code..."
20th Sep 2019, 2:23 PM
Ipang
+ 1
You're very welcome Oladele , Well, I tried a couple of variations before, but only got it working as expected as it was (the 2 condition check first). Please don't take it as a definite way, I'd be happy to see and learn other possibilities one way or another.
23rd Sep 2019, 8:18 AM
Ipang
0
You're very welcome! Please post a feedback here if you find another working variation for the condition checks. I'd be interested to learn 👍
23rd Sep 2019, 9:44 AM
Ipang