July 30, 2022
Примеры задач
row1 = ["⬜️","⬜️","⬜️"]
row2 = ["⬜️","⬜️","⬜️"]
row3 = ["⬜️","⬜️","⬜️"]
map = [row1, row2, row3]
print(f"{row1}\n{row2}\n{row3}")
position = input("Where do you want to put the treasure? ")
vert = int(position[0])
horz = int(position[1])
vert_index=vert-1 # номер элемента в подсписке
horz_index=horz-1 # номер подсписка в списке
selected_row = map[horz_index]selected_row[vert_index] = 'X'
print(f"{row1}\n{row2}\n{row3}")
# второй вариант может быть:
map[horz-1][vert-1] = 'X'Задача 2 Из введенного списка чисел следует выбрать самое большое число
student_scores = input("Input a list of student scores ").split()
for n in range(0, len(student_scores)):
student_scores[n] = int(student_scores[n])
print(student_scores)
highest_score = 0
for score in student_scores:
if score > highest_score:
highest_score = score
# print(highest_score)
print(f"The highest score in the class is: {highest_score}")
rock = '''
_______
---' ____)
(_____)
(_____)
(____)
---.__(___)
'''
paper = '''
_______
---' ____)____
______)
_______)
_______)
---.__________)
'''
scissors = '''
_______
---' ____)____
______)
__________)
(____)
---.__(___)
'''
print("Let's play rock, paper, scissors!")
players_go = input("Now it's your go!\nChoose between rock, paper, scissors:\nType:\nr- for rock\np- for paper\ns-for scissors\n")
goes = {
'r': rock,
'p': paper,
's': scissors
}
def choose_what_to_print(players_go):
return goes.get(players_go,"wrong letter")
print(f"You've chosen: {choose_what_to_print(players_go)}")
print(f'Now, computer goes:')
list_of_var = [rock, paper, scissors]
import random
comp_choice = random.choice(list_of_var)
print(comp_choice)
if players_go =='r' and comp_choice == rock:
print("It's a draw")
elif players_go == 'p' and comp_choice == paper:
print("It's a draw")
elif players_go == 's' and comp_choice == scissors:
print("It's a draw")
else:
if players_go =='r' and comp_choice == scissors:
print('You won')
elif players_go == 'p' and comp_choice == rock:
print('You won')
elif players_go == 's' and comp_choice == paper:
print('You won')
else:
print('You lose!')
if players_go =='r' and comp_choice == rock:
print("It's a draw")
elif players_go == 'p' and comp_choice == paper:
print("It's a draw")
elif players_go == 's' and comp_choice == scissors:
print("It's a draw")
else:
if players_go =='r' and comp_choice == scissors:
print('You won')
elif players_go == 'p' and comp_choice == rock:
print('You won')
elif players_go == 's' and comp_choice == paper:
print('You won')
else:
print('You lose!')
#Password Generator Project
import random
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
symbols = ['!', '#', '#39;, '%', '&', '(', ')', '*', '+']print("Welcome to the PyPassword Generator!")
nr_letters= int(input("How many letters would you like in your password?\n"))
nr_symbols = int(input(f"How many symbols would you like?\n"))
nr_numbers = int(input(f"How many numbers would you like?\n"))
# надо создать три списка, потом их объединить, перевести во множество и выдать результат
letter_ran_spisok=[]
for i in range(0, nr_letters):
letter_ran_spisok.append(random.choice(letters))
symbols_ran_spisok=[]
for i in range(0,nr_symbols):
symbols_ran_spisok.append(random.choice(symbols))
numbers_ran_spisok=[]
for i in range(0,nr_numbers):
numbers_ran_spisok.append(random.choice(numbers))
# making new list joining the above lists and turning it in set
password=''.join(set(letter_ran_spisok+symbols_ran_spisok+numbers_ran_spisok))
print(password)Ниже еще два варианта решения этой задачи:
#Password Generator Project
import random
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l'
, 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N'
, 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
symbols = ['!', '#', '#39;, '%', '&', '(', ')', '*', '+']
print("Welcome to the PyPassword Generator!")
nr_letters = int(input("How many letters would you like in your password?\n"))
nr_symbols = int(input(f"How many symbols would you like?\n"))
nr_numbers = int(input(f"How many numbers would you like?\n"))
#Eazy Level
# password = ""
# for char in range(1, nr_letters + 1):
# password += random.choice(letters)
# for char in range(1, nr_symbols + 1):
# password += random.choice(symbols)
# for char in range(1, nr_numbers + 1):
# password += random.choice(numbers)
# print(password)
#Hard Level
password_list = []
for char in range(1, nr_letters + 1):
password_list.append(random.choice(letters))
for char in range(1, nr_symbols + 1):
password_list += random.choice(symbols)
for char in range(1, nr_numbers + 1):
password_list += random.choice(numbers)
print(password_list)
random.shuffle(password_list)
print(password_list)
password = ""
for char in password_list:
password += char
print(f"Your password is: {password}")July 30, 2022, 10:23
0 views
0 replies
0 reposts