ProgrammingModerateGATE CS · Product-company placement
What is printed?
What is printed?
print(divmod(-17, 5), divmod(17, -5), -17 % -5, pow(3, -1, 7))
- A. (-3, -2) (-3, 2) -2 5
- B. (-4, 3) (-4, -3) -2 5
- C. (-4, 3) (-3, -2) -2 5
- D. (-4, 3) (-3, 2) -2 ValueError
Correct answer: B. (-4, 3) (-4, -3) -2 5
// floors toward minus infinity and % takes the sign of the divisor: -17 = 5*(-4) + 3 and 17 = (-5)*(-4) - 3. pow(3, -1, 7) is the modular inverse of 3 mod 7, which is 5 (3*5 = 15 = 1 mod 7).
More Python Programming questions
- What is printed? python print(not 1 == 2, not (1 == 2) is True, (not 1) == 2, 1 + True + True)
- What is printed? python x = 5 print(1 < x < 10 > 3 != 4, 3 > 2 > 1 == True, (3 > 2) > (1 == True), 0 == 0 in [0])
- What is printed? python s = "a,b,,c," print(len(s.split(",")), len(s.split()), s.rsplit(",", 2)[0], s.partition(";")[0] == s)
- What is printed? python s = "a btcn" print(s.split(), len(s.split(" ")), len(s.strip(" ")), len(s.strip()))
- What is printed? python print("ß".upper(), "ß".casefold() == "SS".casefold(), "fi".upper(), len("ß".upper()))
- What is printed? python print("abc" -1 == "", [0] 0, "b" in "abc", "" in "abc", "abc".find(""), "abc".count(""))