20 Answers
New Answerhttps://code.sololearn.com/cj2Zm5YLiJ4I/?ref=app
2/26/2021 5:29:49 PM
Abhishek Singh20 Answers
New Answeryour code is also working. just instead of the right phrase SoloLearn, you wrote Sololearn. this is also important
You will need to use two range for solving. Showed below: # for x in range(1, n,2): [correction in code needed] By using this approach also, you can solve it. However, you will need to take 2 range. Without range 1, n, 2 (won't get solved) 👇 n = int(input()) for x in range(1,n,2): if x % 3 == 0 and x % 5 == 0: print("SoloLearn") elif x % 3 == 0: print("Solo") elif x % 5 == 0: print("Learn") else: print(x)
Ярослав Вернигора(Yaroslav Vernigora) While solving I took reference from here: Python's range() Parameters The range() function has two sets of parameters, as follows: https://www.pythoncentral.io/pythons-range-function-explained/ It has shown, how ranges works in conditioned for loops range(stop) stop: Number of integers (whole numbers) to generate, starting from zero. eg. range(3) == [0, 1, 2]. range([start], stop[, step]) start: Starting number of the sequence. stop: Generate numbers up to, but not including this number. step: Difference between each number in the sequence. --------------- So, to skip even numbers in code... when we already have multiplie by 3 & 5. We usually do even number with multiple of 2. This way, my problem was solved. For increments we usually do something like "range(1, n+1)". I did it using [2 as step] in for loop. Start with 1 Stop with n (input) Step by using 2
བསོད་ནམ་བཀྲ་ཤིས། well your code now even prints even numbers which should be skipped ☺
Here is the correct code : n = int(input()) for x in range(1, n): if x % 2 == 0: continue if x % 3 == 0 and x % 5 == 0: print("SoloLearn") elif x % 3 == 0: print("Solo") elif x % 5 == 0: print("Learn") else: print(x)
Thx Shivani 📚✍ [Less Active] For your help It worked My code gives same output but fails in secobd test don't know why but Thank you very much
Hi! his code is correct. he works. tell you where the error is?
Shivani 📚✍ [Less Active] explain why in the condition of the cycle you put after n, -> 2? what does that give?
SoloLearn Inc.
4 Embarcadero Center, Suite 1455Send us a message