TIME NOW
World current time now,
CALENDAR
Calendar monthly, yearly
login CONVERT LENGTH
login CONVERT TEMPERATURE
login DICTIONARIES, LISTS
login SCIENCE EDUCATION RELIGION
login WORK CALCULATOR
login CALCULATE LIFE

Python 3 programming language, learn python, tutorial

Previous articlePage bottomNext article  ALL TOPICS

Python 3. Tasks, Exercises

 1. Draw a game board. After entering number, it is added or removed. If twice deleted - no effect, if twice added- no effect:

  ---   ---   ---
|  1  |  2  |  3  |
  ---   ---   ---  
|  4  |  5  |  6  |
  ---   ---   ---  
|  7  |  8  |  9  |
  ---   ---   ---

Exit - 0. Enter number to delete, (example d1). Enter number to add (example - a1):

Data format:
d1
a9

2. Draw a game board with dynamic width and height:
  ----   ----   ----
|  01  |  02  |  03  |
  ----   ----   ----
|  04  |  05  |  06  |
  ----   ----   ---- 
|  07  |  08  |  09  |
  ----   ----   ----

Enter width and height (min = 2x2, max 6x8):

Data format:
3,5
4,4

3. Draw a histogram. Program takes a list of integers and prints a histogram to the screen. It can be processor's load from  0 to 10 stars. Lenght of list can change. Third column is set, when PROC1 + PROC2 >=10. For example, list1 = [4, 9, 7] and list2= [5,2,1] should print the following:  
PROC1       | PROC2     |
****        | *****     |
*********   | **        | x
*******     | *         |

4. Write a program that changes a sentennce of words into a list of integers, representing the lengths of the correponding words.
"Mano batai buvo du. Niekur eiti negaliu???" is converted to [4,4,4,2,6,4,7]. Calculate frequency of the words and sort: {2:1, 4:2, 6:1, 7:1}.

5. Write function, which generates HTML table from row "nafta - 50EUR, bendzinas - 100EUR, dujos - 60EUR, auksas - 110EUR". Values and amount of pairs can change. If value
is > 100, it is marked as HTML red, if values is < 30, it is marked as HTML green. Even and odd rows are colored differently:
nafta 50
bendzinas 100
dujos 60
auksas 110

HTML:
<table border="1">
<tbody>
<tr>
<td style="background-color:#D3D3D3;"><span>nafta</span></td>
<td style="background-color:#D3D3D3;"><span>50</span></td>
</tr>
<tr>
<td>bendzinas</td>
<td>100</td>
</tr>
<tr>
<td style="background-color:#D3D3D3;">dujos</td>
<td style="background-color:#D3D3D3;">60</td>
</tr>
<tr>
<td>auksas</td>
<td><span style="color:#FF0000;">110</span></td>
</tr>
</tbody>
</table>

6. Write a function, which shows overlapping elements from two lists. Another function shows different elements from both lists. 
list1 = [1,2,3,4,5]
list2 = [5,2,5,1,5,1]

def compare(*lists):

    def overlap():
        pass
    
    def different():
        pass 

    overlap()
    different()

compare (list1, list2)
 

7. Write a function to solve a classic ancient Chinese puzzle:
We count 35 heads and 94 legs among the chickens and rabbits in a farm. How many rabbits and how many chickens do we have?

8. Write function. With a given list [12,24,35,24,88,120,155,88,120,155], write a program to print this list leaving all duplicate values with original order reserved. 
Previous articlePage topNext article  ALL TOPICS


Andrius:
2.
list = [4, 9, 7]
for n, b in enumerate(list, 1):
print(n,'*'* b)

5.
b1 = [1,2,3,4,5,9,11,15]
b2 = [4,5,6,7,8]
def intersect(a, b):
    return list(set(a) & set(b))
print (intersect(b1, b2))

b1 = [1,2,3,4,5,9,11,15]
b2 = [4,5,6,7,8]
def diff(a, b):
    xa = [i for i in set(a) if i not in b]
    xb = [i for i in set(b) if i not in a]
    return xa + xb
print (diff(b1, b2))


2015-11-09 08:20:15
Vitalij:
<1>
s=" "
list=[s,s,s,s,s,s,s,s,s]
n=0 #X ar O
lp=0 #0<X<10 Loop
main=0 #main loop
eql=0 #Nowin
player=0 #player

def win(ox):
#x
if list[0]==ox and list[1]==ox and list[2]==ox:
return 1
if list[3]==ox and list[4]==ox and list[5]==ox:
return 1
if list[6]==ox and list[7]==ox and list[8]==ox:
return 1
#y
if list[0]==ox and list[3]==ox and list[6]==ox:
return 1
if list[1]==ox and list[4]==ox and list[7]==ox:
return 1
if list[2]==ox and list[5]==ox and list[8]==ox:
return 1
#xy
if list[0]==ox and list[4]==ox and list[8]==ox:
return 1
if list[2]==ox and list[4]==ox and list[6]==ox:
return 1
return 0

def prnt(x):
print(" ---"*3,"\n |",list[0],"|",list[1],"|",list[2],"|\n"," ---"*3)
print(" |",list[3],"|",list[4],"|",list[5],"|\n"," ---"*3)
print(" |",list[6],"|",list[7],"|",list[8],"|\n"," ---"*3)
return x+1
def cik(z):
for w in range(len(list)):
if list[w]=="X" or list[w]=="O":
z+=1
return z

while True:
player=int(input("Zaideju skaicius 1 ar 2?"))
if player==1 or player==2:
break
else:
print("1 - Zaidejas vs Kompiuteris\n2 - Zaidejas vs zaidejas")
while main==0:
if n%2==0:
prnt(n)
while lp==0:
x=int(input("Kur bus jusu X? Nuo 1 iki 9: "))
if x>0 and x<10:
if list[x-1]==s:
list[x-1]="X"
lp+=1
else:
if player==2:
prnt(n)
while lp==0:
if player==1:
from random import randint
x=randint(0,10)
else:
x=int(input("Kur bus jusu O? Nuo 1 iki 9: "))
if x>0 and x<10:
if list[x-1]==s:
list[x-1]="O"
lp+=1
lp=0
n+=1
if main==0:
main = win("X")
if main==1:
prnt(n)
print("Laimejo X")
if main==0:
main = win("O")
if main==1:
prnt(n)
print("Laimejo O")
if main==0:
eql=0
if cik(eql)==9:
prnt(n)
print("Laimetoju nera :C")
main=1;
<3>==========================================================

list=['vilniaus','verslo','kolegija','vvk','python','programa','kodas']
print(list)
for x in range(len(list)):
list[x]=len(list[x])
print(list)


2015-11-09 09:24:23

 Use username: Guest, Anonymous, Programmer






QUOTES:
Tact is the intelligence of the heart.
Anonymous
In order to be walked on, you have to be lying down.
Brian Weir
t is great happiness to be praised by them who are most praiseworthy.
Sir Philip Sidney