 How would I write this line of code in Python? | Sololearn: Learn to code for FREE!

+16

# 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!!

+80

+22

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

+15

+9

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.

+8

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

+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

+4

print(7%(5//2)) It is like this because you put whatever you want to print in between the brackets.

+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.

+2

+2

[5//2] is a error, because is for lists print(7%(5//2)) Because: Is () because is a expresion matematical

+2

+2

Fabián Tienes toda la razón.

+2

print( 7 % ( 5 // 2 ) ) you can use the spaces for better reading ~

+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))

+1

+1

+1

+1

+1

Print(7%(5//2)) 7%5//2 7%(2) 7%2 =3remainder1 Answer=1