Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Lesson 2-ex
#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. # * # ** # *** # **** #solution #1 #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('****') #solution #2 x=0 while x<20: x = x + 1 #print('x=',x) if 4<x<=5: print('*') elif 9<x<=10: print('**') elif 14<x<=15: print('***') elif 19<x<=20: print('****')
run
|
edit
|
history
|
help
0
Lab_I_1_25_11_2020
Saurabh
Sir, You Are Being Hunted secret message
My Personal data
Algorytm szybkiego potęgowania
PyBatScoreSOLID
Gift_Card Interview SQL Analysis Conducted by Miranda Zhao
вложенные циклы Квадрат
Helloworld
p1