Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Exercise 4 for lesson 2
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
#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: #
[
+
]
Show input
Absolute running time: 0.2 sec, cpu time: 0.16 sec, memory peak: 6 Mb, absolute service time: 0,21 sec
edit mode
|
history
|
discussion
* * * * * ** ** ** ** ** *** *** *** *** *** **** **** **** **** ****