What is the output of this code? >>> x = 3 >>> num = 17 >>> print(num % x) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 18

What is the output of this code? >>> x = 3 >>> num = 17 >>> print(num % x)

31st Oct 2016, 3:58 PM
Prajwal Kumar
Prajwal Kumar - avatar
44 Answers
+ 43
2, because if you divide 17 by 3 the remainder will be 2 and this sign % counts the remainder
31st Oct 2016, 4:44 PM
Suzie
Suzie - avatar
+ 8
I don't know how the program works in detail (is that your question?) but there are few possibilities to see what % does. As example with your code 1.1) _ _ 17:3=5,6 0,6×3=2 1.2) _ 17:3=5,6 round down->5×3=15 -> 17-15=2 2) 17:3=5 -15 ----- 2 I hope it's helpful 😅
4th Nov 2016, 2:41 PM
cocoacheescakemuffin
cocoacheescakemuffin - avatar
+ 5
The answer is 2 This is because the % operator returns the remainder of the two numbers it is dividing. in your code you are asking what the remainder is when you divide 17 by 3 3 can go into 17 five times, which would make 15. Then the operator takes 17 and 15 and finds the difference between the two, 17-15 = 2
15th Dec 2016, 7:05 PM
Gabriel Peri
Gabriel Peri - avatar
+ 4
well, thats because this sign % returns the remainder, thats its function, and the print function is used to print out a value to the screen.. How else can she explain more? what details do you want to know?
31st Oct 2016, 8:19 PM
Adam Salehe
Adam Salehe - avatar
+ 3
it will 2 according to math
16th Dec 2016, 9:49 PM
nitin kalasi
+ 2
The answer is 2 because % is mod operator which returns remainder. 3*5=15 and remainder is 2.
30th Jan 2017, 8:36 PM
Cumul O Nimbus
Cumul O Nimbus - avatar
+ 1
% is the modulus operator which returns remainder. so when 17 is divided by 3 remainder is 2.
8th Feb 2017, 3:31 PM
Bharath Kumar
Bharath Kumar - avatar
+ 1
2
11th Mar 2017, 11:24 AM
shyam goyner
shyam goyner - avatar
+ 1
The answer is 2 for the record
27th Oct 2017, 7:50 PM
Das Man
Das Man - avatar
+ 1
2
7th May 2019, 12:45 PM
twins gaming/hack
twins gaming/hack - avatar
+ 1
2
2nd May 2020, 12:27 PM
Ahmed
Ahmed - avatar
0
i know its 2 but tell me how
31st Oct 2016, 3:59 PM
Prajwal Kumar
Prajwal Kumar - avatar
0
2
5th Nov 2016, 10:12 AM
Дормидонтов Даниил
Дормидонтов Даниил - avatar
0
sorry, the output is 2, because 3*5= 15, 17-15 = 2 if your num is 18, the output will be 0 because 3*6 = 18, 18-18 = 0
6th Nov 2016, 11:05 PM
Alexander Nicholas S.
Alexander Nicholas S. - avatar
0
% the modulus, returns the reminder,. so ans is obviously 2
10th Nov 2016, 5:32 PM
Mahfuz Ahmed
0
2 the answer
14th Nov 2016, 4:58 PM
mustafa hk
mustafa hk - avatar
0
its simple % this sign is called modulus it is used to obtain the remainder 17%3 means you want to know the remainder when 17 is divided by 3 well the closest whole number where 3 is giving is 15 and 17-15=2 that's how it is giving 2
14th Nov 2016, 5:03 PM
mustafa hk
mustafa hk - avatar
0
x = 3, num = 17 Here you are giving 17 as num, which is not exactly divisible by 2 Well finally you want to print the reminder So, 17/3 = 15 and 17-15 = 2 Hence 2 is the output/reminder
17th Nov 2016, 5:55 AM
sanjay
sanjay - avatar
0
2
20th Nov 2016, 1:02 AM
Ufuk Hürriyetoğlu
Ufuk Hürriyetoğlu - avatar
0
it is 2 it is easy 17%3 = 2 which is the remainder of the division process
21st Nov 2016, 7:16 AM
Hatem Mohamed
Hatem Mohamed - avatar