Post

Python Programming
Python Programming@PythonPr·
Python Question / Quiz; What is the output of the following Python code, and why? Comment your answers below!
Python Programming tweet media
English
26
9
125
10.9K
Earnest Codes
Earnest Codes@Earnesto037·
@PythonPr Answer: (D) [10, 20, 0, 10, 20] The code uses a list comprehension to create List2 based on the values in List1 [3]. The expression n%30 calculates the modulo of each number n by 30 [3]. Here's how each element is processed: 10 % 30 equals 10. 20 % 30 equals 20.
English
1
0
7
252
Kamal Gurjar
Kamal Gurjar@KamalGurjar8·
@PythonPr Answer: D) [10, 20, 0, 10, 20] Explanation: The list comprehension applies modulo % 30 to each element in List1: 10 % 30 = 10 20 % 30 = 20 30 % 30 = 0 40 % 30 = 10 50 % 30 = 20 So the resulting list is [10, 20, 0, 10, 20].
English
0
0
4
377
TSowell Fan
TSowell Fan@TSowellFan·
@PythonPr Guessing D tho I haven't yet seen the syntax in the List2 line yet in my Python learning. But, IIRC, % is the modulo operator. And the 'for' implies stepping through the List1 entries.
English
0
0
2
255
Uday Sharma
Uday Sharma@udaysharmatech·
@PythonPr Output is [10, 20, 0, 10, 20]. Each element is taken modulo 30.
English
0
0
0
131
CodeToRobots
CodeToRobots@CodeToRobots·
@PythonPr D Modulus returns the remainder after division. For n in list1 loops through list1 assign each index in the list to n the. List 2 finds the mudulus 30.
English
0
0
0
77
分享