Постови

Приказују се постови за децембар, 2019

Python game hangman

Build a list of countries L and program which is going to simulates game hangman. from random import choice L = [ 'Holland' , 'Croatia' , 'Afghanistan' , 'Ireland' , 'Italy' , 'Hungary' ] country = choice(L) ending = list(country) help_1 = '' for i in range(len(country)):     help_1 = help_1 + '-' print(help_1) help_1 = list(help_1) guess = '' K = [] while ending != help_1:     guess = input( 'Enter a letter!' )     if guess in country:         K = list(country)         for i in range(len(K)):             if K[i] == guess:                 t = i                 help_1[t] = guess               ...

Change entries in list Python

Build a list L which should contain 7 integers 0 and 1. Write program to check is there different entries than 0 and 1 and if is, change that entries to 1. L = [0, 1, 2, 1, 4, 0, 3] i = 0 while i < len(L):     if L[i] == 0:         pass     elif L[i] == 1:         pass     else :         L[i] = 1     i += 1 print(L) [0, 1, 1, 1, 1, 0, 1]   

Python multidimensional list random changing entries

Built 5x5 list of zeroes and randomly changes exactly ten of those zeroes to ones. L = [[0 for i in range(5)] for j in range(5)] c = 0 p = 0 for i in range(len(L)):     for j in range(len(L)):         print(L[i][j], end= ' ' )     print() print() for i in range(len(L)):     for j in range(len(L)):         while c < 10:             i = randint(0, len(L) - 1)             j = randint(0, len(L)-1)             if L[i][j] == 0:                 L[i][j] = 1                 c = c + 1 for i in range(len(L)):     for j in range(len(L)): ...

Python prime numbers

How to find 1000th prime prime = [] not_prime = [] one_thousand = 0 i = 2 for broj in range(2, 10000): while i < broj and broj%i != 0: i += 1 if i == broj: prime.append(broj) if len(prime) == 1000: one_thousand = prime[-1:] break else : not_prime.append(broj) i = 2 print(one_thousand) One thousand prime number is: [7919]