Download presentation
Presentation is loading. Please wait.
Published byGregory Hunt Modified over 9 years ago
1
AE1205 Programming Python Quiz: so how do we generate Numbers 1 to 10? range( ) Numbers 5,10,15,20,25 to 100? range( ) Numbers 20,18,16, to 0? range( ) 1
2
AE1205 Programming Python Quiz: so how do we generate Numbers 1 to 10? range(1,11) Numbers 5,10,15,20,25 to 100? range( ) Numbers 20,18,16, to 0? range( ) 2
3
AE1205 Programming Python Quiz: so how do we generate Numbers 1 to 10? range(1,11) Numbers 5,10,15,20,25 to 100? range(5,105,5) or range(5,101,5) Numbers 20,18,16, to 0? range( ) 3
4
AE1205 Programming Python Quiz: so how do we generate Numbers 1 to 10? range(1,11) Numbers 5,10,15,20,25 to 100? range(5,105,5) or range(5,101,5) Numbers 20,18,16, to 0? range(20,-2,-2) 4
5
AE1205 Programming Python Quiz: What will this print? print sum(range(1,11)) 5
6
AE1205 Programming Python Quiz: What will this print? print sum(range(1,11)) 6 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10
7
AE1205 Programming Python Quiz: What will this print? print sum(range(1,11)) 7 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 10 + 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1 Dus 10*11/2 = 55 So what does this print? print sum(range(1,101))
8
AE1205 Programming Python Quiz: What will this print? print sum(range(1,11)) 8 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 10 + 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1 Dus 10*11/2 = 55 So what does this print? print sum(range(1,101)) 5050
9
AE1205 Programming Python Quiz: what will this print? s=0 for x in range(3): for y in range(3): s = s + 1 print x,y print s,x,y Check http://www.pythontutor.com 9 Answer: 0 0 1 0 2 1 0 1 1 2 2 0 2 1 2 9 2 2 This is called: nested loops
10
AE1205 Programming Python Quiz: What will this print? x = 0. while x+5 > x*x: print x x = x + 1. 10
11
AE1205 Programming Python Quiz: What will this print? x = 0. while x+5 > x*x: print x x = x + 1. 11
12
AE1205 Programming Python Quiz: What will this print? x = 0. while x+5 > x*x: print x x = x + 1. 12
13
AE1205 Programming Python Quiz: What will this print? x = 0. while x+5 > x*x: print x x = x + 1. >>> 0.0 1.0 2.0 13
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.