Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Exercise 4 for lesson 2
#python 3.5.2 # https://1drv.ms/f/s!ArsHV2FdZgQ1iQOclKKq2kqbxLdg # Loops - For Loops x = [1, 2, 7, 9, 10, 3, 14] y = [] # x and y are lists # Exercise 1 # ------------- # 1. Create a list of numbers. 2. Compute the squares for each number in the list. 3. Then print the list. q = [] m = [] for each_n in range(1, 20, 3): q.append(each_n) # my list of numbers m.append(each_n*each_n) # my list of numbers squared #print ("q = ", q) #print ("m = ", m) # Exercise 2 # ------------- # Create a list of 20 numbers - [1,20]. If the number is even, print "Even". If the number is odd, print "Odd". # [modulo operation] if number%2 == 0: then even, elif number%2 == 1, then odd. for each_i in range (20): if each_i%2 == 0: pass #print ( each_i, 'is even.') elif each_i%2 == 1: pass #print ( each_i, 'is odd.') # Exercise 3 # ------------- # while condition is true: # keep doing something # (have something that will change the condition later) #count = 0 #while count < 5: # print (count) # count = count + 1 # count increased its value by 1 # Exercise 4 # --------------- # Use a while/for loop to print this diagram. You will need to use if conditions also. # * # ** # *** # **** x=0 while x<20: x = x + 1 #print('x=',x) if x<=5: print('*') elif 5<x<=10: print('**') elif 10<x<=15: print('***') elif 15<x<=20: print('****') # for i in x: #
run
|
edit
|
history
|
help
0
HW selectionsort using while
Minesweeper
RNG
Интересный Python - Вопрос 1
Prime numbers
Breadth-First Path Finding
gj
guess123
Lesson 6 part b2
Python code