How would I write this line of code in Python? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 21

How would I write this line of code in Python?

What would this look like typed out in a text editor, to solve? I already have the answer (1) but want to know how to do this correctly & for the future. 7%(5//2) I tried print 7%(5//2) but it's saying that's incorrect. I also tried print[7%(5//2)] and that came up with an error. Any help would be appreciated. Thanks!!

2nd Nov 2016, 11:42 PM
Colleen
Colleen - avatar
142 Answers
+ 98
print(7%(5//2))
3rd Nov 2016, 12:42 AM
Anastasios Glaros
Anastasios Glaros - avatar
+ 25
print(7%(5//2)) Replace "[ ]" brackets with "( )" brackets, following print . First the internal part (5//2) will be executed by geting an output 2(quotient) and then the external part (7%2) will be executed and outputs 1
24th Mar 2021, 6:05 PM
Cherukuri Gouri
Cherukuri Gouri - avatar
+ 15
print (7%(5//2))
14th Mar 2021, 6:13 AM
Константин Бабаян
Константин Бабаян - avatar
+ 12
Print(7%(5//2)) You need parentheses around your main line. And what you want the program to sovle first. So Line 1. Print() Then you want to add 7%(5//2) <—This gose within the above parentheses from line 1. So itll look like Line 1. Print(7%(5//2)) I would like to use brackets to seperate the process but ikd. Im just learning.
12th Apr 2021, 10:27 AM
Reginald Gray
+ 10
To get output of ( 7%(5//2)) First you have to know operator precedence in Python "PEMDAS" is a short form to know when you execute operational statements P - Parenthesis ---> ( ) E - Exponential ---> (**) M - Multiplication ---> * D - Division ---> /(Normal Division) or //(Floor Division) A - Addition ---> + S - Subtraction ---> - ( 7%(5//2) ) 1.First it will execute within parenthesis i.e. 5//2 -> 2 (takes quotient as output) In Python3, 5/2 returns float vale as output => 5/2 = 2.5 5//2 returns integer as output => 5//2 = 2 2. Next it will execute (7%2) Here %(Modulus) will take remainder as output -> 7%2 => 1(remainder) ,3(quotient) 3. Finally it will return 1 as output value (7%(5//2)) -> (7%2) -> 1
21st Jul 2021, 9:29 AM
Sagar S
Sagar S - avatar
+ 5
for getting answer you need {print() } function for your example : print(7%(5//2)) explaining code: at first it calculate how many 2 come in 5 because of () and // then it calculate The remainder is divided by 7 to 2
14th Mar 2021, 1:09 PM
Ali Kabiri
Ali Kabiri - avatar
+ 4
print(7%(5//2)) It is like this because you put whatever you want to print in between the brackets.
19th Aug 2021, 3:57 PM
Shrey
+ 2
print(7%(5//2)) It will count those inside the parenthesis 5//2 which is 2. Then in 7%2 it will divide it and find its remainder which is 1.
25th Mar 2021, 12:37 PM
Marvin Gajelomo
Marvin Gajelomo - avatar
+ 2
simply use BODMAS
30th Mar 2021, 3:58 AM
sanjay gobari
sanjay gobari - avatar
+ 2
print(7%(5//2))
1st Apr 2021, 2:14 PM
Rakesh E M
Rakesh E M - avatar
+ 2
print(7%(5//2))
25th Aug 2021, 5:59 AM
Daniel Ephraim VAUGHN
Daniel Ephraim VAUGHN - avatar
+ 2
[5//2] is a error, because is for lists print(7%(5//2)) Because: Is () because is a expresion matematical
26th Aug 2021, 12:04 AM
CGO!
CGO! - avatar
+ 2
print(7 % (5 // 2))
26th Aug 2021, 5:32 AM
Ashuraliyev Alisherjon
+ 2
Fabián Tienes toda la razón.
4th Oct 2021, 10:47 PM
CGO!
CGO! - avatar
+ 2
print( 7 % ( 5 // 2 ) ) you can use the spaces for better reading ~
31st Dec 2021, 6:34 AM
Kennedy Keyes
+ 2
print(7%(5//2))
21st Sep 2022, 3:39 PM
Jiovany Pe
Jiovany Pe - avatar
+ 1
First use print() to print any result. And ofcourse you must include those round brackets () to print. Now as per your problem it'd be print(7%(5//2))
18th Mar 2021, 7:17 PM
STEEL FOCUS
STEEL FOCUS - avatar
+ 1
print (7%(5//2))
30th Mar 2021, 11:57 AM
Devika Reddy
Devika Reddy - avatar
+ 1
print(7%(5//2))
30th Mar 2021, 8:27 PM
Sonu Kumar
Sonu Kumar - avatar
+ 1
Print (7%(5//2))
14th Apr 2021, 2:03 PM
Mayank Hemnani
Mayank Hemnani - avatar