Lecture 04

In [1]:
for i in range(1,5,1):
    for j in range(1,5,1):
        print('* ',end='')
    print()
* * * * 
* * * * 
* * * * 
* * * * 
In [2]:
for i in range(1,5,1):
    for j in range(1,i+1,1):
        print('* ',end='')
    print()
* 
* * 
* * * 
* * * * 
In [3]:
for i in range(1,5,1):
    for j in range(1,5-i,1):
        print('  ',end='')
    for j in range(1,i+1,1):
        print('* ',end='')
    print()
      * 
    * * 
  * * * 
* * * * 
In [4]:
name='ali ghorbani'
for i in range(len(name)):
    if name[i]!=' ':
        print(name[i],end='')
    else:
        break
ali
In [5]:
l1=[0,1,0,1,1,1,0,1,1]
for i in range(len(l1)):
    if l1[i]==1:
        print('OK ',end='')
    else:
        continue
    print('done')
    print()    
OK done

OK done

OK done

OK done

OK done

OK done

In [6]:
name=['ali','hasan','reza','ahmad','alireza','karim']
for i in range(len(name)):
    print(name[i],end=' ')
    if len(name[i])<5:
        print('khoobi? ')
        continue
    elif len(name[i])<6:
        print('chekhabar? ')
        continue
    break
        
ali khoobi? 
hasan chekhabar? 
reza khoobi? 
ahmad chekhabar? 
alireza 

$\sum_{i=0}^{n}(3i^2+1)$

In [7]:
n=2
s1=0
for i in range(0,n+1,1):
    d=3*i**2+1
    s1=s1+d
print(s1)
18
In [8]:
def f(x):
    a=x**2
    return a
In [9]:
f(2)
Out[9]:
4
In [10]:
f(3)
Out[10]:
9
In [11]:
def f(x,y):
    return x**2+y