PRO_PYTHON_CODE Telegram 1034
🐍 10 проектов на Python для начинающих

1. Игра “Виселица

Инструкции: Создайте классическую игру “Виселица”. Предложите пользователю угадывать слово по буквам до тех пор, пока он не угадает его правильно или пока не закончатся попытки.
import random

def hangman():
words = ['python', 'hangman', 'programming', 'code']
word = random.choice(words)
guesses = ''
attempts = 6

while attempts > 0:
for char in word:
if char in guesses:
print(char, end=' ')
else:
print('_', end=' ')
print()

guess = input("Guess a letter: ")
guesses += guess

if guess not in word:
attempts -= 1

if set(word) <= set(guesses):
print("Congratulations! You guessed the word.")
break
elif attempts == 0:
print("Sorry, you ran out of attempts. The word was", word)

hangman()


2. Калькулятор


Инструкции: Постройте простой калькулятор, выполняющий основные арифметические операции (+, -, *, /) над двумя числами.
def calculator():
num1 = float(input("Enter the first number: "))
operator = input("Enter an operator (+, -, *, /): ")
num2 = float(input("Enter the second number: "))

if operator == '+':
print(num1 + num2)
elif operator == '-':
print(num1 - num2)
elif operator == '*':
print(num1 * num2)
elif operator == '/':
print(num1 / num2)
else:
print("Invalid operator")

calculator()


3. Угадайте число

Инструкции: Создайте игру, в которой компьютер генерирует случайное число, а игрок пытается угадать его за определенное количество попыток.
import random

def guess_the_number():
number = random.randint(1, 100)
attempts = 0

while True:
guess = int(input("Take a guess: "))
attempts += 1

if guess < number:
print("Too low!")
elif guess > number:
print("Too high!")
else:
print("Congratulations! You guessed the number in", attempts, "attempts.")
break

guess_the_number()

4. Список дел

Инструкции: Создать приложение для составления списка дел, позволяющее пользователю добавлять, просматривать и удалять задачи.
def todo_list():
tasks = []

while True:
print("1. Add a task")
print("2. View tasks")
print("3. Remove a task")
print("4. Quit")

choice = input("Enter your choice: ")

if choice == '1':
task = input("Enter a task: ")
tasks.append(task)
elif choice == '2':
if tasks:
print("Tasks:")
for task in tasks:
print(task)
else:
print("No tasks.")
elif choice == '3':
if tasks:
task = input("Enter the task to remove: ")
if task in tasks:
tasks.remove(task)
print("Task removed.")
else:
print("Task not found.")
else:
print("No tasks.")
elif choice == '4':
break
else:
print("Invalid choice. Try again.")

todo_list()


Продолжение

@pro_python_code
🔥8👍61



tgoop.com/pro_python_code/1034
Create:
Last Update:

🐍 10 проектов на Python для начинающих

1. Игра “Виселица

Инструкции: Создайте классическую игру “Виселица”. Предложите пользователю угадывать слово по буквам до тех пор, пока он не угадает его правильно или пока не закончатся попытки.
import random

def hangman():
words = ['python', 'hangman', 'programming', 'code']
word = random.choice(words)
guesses = ''
attempts = 6

while attempts > 0:
for char in word:
if char in guesses:
print(char, end=' ')
else:
print('_', end=' ')
print()

guess = input("Guess a letter: ")
guesses += guess

if guess not in word:
attempts -= 1

if set(word) <= set(guesses):
print("Congratulations! You guessed the word.")
break
elif attempts == 0:
print("Sorry, you ran out of attempts. The word was", word)

hangman()


2. Калькулятор


Инструкции: Постройте простой калькулятор, выполняющий основные арифметические операции (+, -, *, /) над двумя числами.
def calculator():
num1 = float(input("Enter the first number: "))
operator = input("Enter an operator (+, -, *, /): ")
num2 = float(input("Enter the second number: "))

if operator == '+':
print(num1 + num2)
elif operator == '-':
print(num1 - num2)
elif operator == '*':
print(num1 * num2)
elif operator == '/':
print(num1 / num2)
else:
print("Invalid operator")

calculator()


3. Угадайте число

Инструкции: Создайте игру, в которой компьютер генерирует случайное число, а игрок пытается угадать его за определенное количество попыток.
import random

def guess_the_number():
number = random.randint(1, 100)
attempts = 0

while True:
guess = int(input("Take a guess: "))
attempts += 1

if guess < number:
print("Too low!")
elif guess > number:
print("Too high!")
else:
print("Congratulations! You guessed the number in", attempts, "attempts.")
break

guess_the_number()

4. Список дел

Инструкции: Создать приложение для составления списка дел, позволяющее пользователю добавлять, просматривать и удалять задачи.
def todo_list():
tasks = []

while True:
print("1. Add a task")
print("2. View tasks")
print("3. Remove a task")
print("4. Quit")

choice = input("Enter your choice: ")

if choice == '1':
task = input("Enter a task: ")
tasks.append(task)
elif choice == '2':
if tasks:
print("Tasks:")
for task in tasks:
print(task)
else:
print("No tasks.")
elif choice == '3':
if tasks:
task = input("Enter the task to remove: ")
if task in tasks:
tasks.remove(task)
print("Task removed.")
else:
print("Task not found.")
else:
print("No tasks.")
elif choice == '4':
break
else:
print("Invalid choice. Try again.")

todo_list()


Продолжение

@pro_python_code

BY Python RU


Share with your friend now:
tgoop.com/pro_python_code/1034

View MORE
Open in Telegram


Telegram News

Date: |

How to Create a Private or Public Channel on Telegram? Read now Telegram desktop app: In the upper left corner, click the Menu icon (the one with three lines). Select “New Channel” from the drop-down menu. Some Telegram Channels content management tips To delete a channel with over 1,000 subscribers, you need to contact user support
from us


Telegram Python RU
FROM American