0% found this document useful (0 votes)
2 views4 pages

4

The document presents five Python code examples showcasing different functionalities: an email address validator, a rock-paper-scissors game, a prime number checker, a random password generator, and a simple console-based to-do list app. Each example includes code snippets and brief descriptions of their purpose. Additionally, it offers to provide more targeted examples related to specific topics like machine learning or data visualization.

Uploaded by

hsgstgas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

4

The document presents five Python code examples showcasing different functionalities: an email address validator, a rock-paper-scissors game, a prime number checker, a random password generator, and a simple console-based to-do list app. Each example includes code snippets and brief descriptions of their purpose. Additionally, it offers to provide more targeted examples related to specific topics like machine learning or data visualization.

Uploaded by

hsgstgas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Here are **five more Python code examples** with different

:functionalities

**Email Address Validator** .1 ###

.Checks if an email is In a valid format

python```

Import re

Email = input("Enter an email address: ")

'$+Pattern = r'^[\w\.-]+@[\w\.-]+\.\w

:If re.match(pattern, email)

Print("Valid email.")

:Else

Print("Invalid email.")

```

**Rock-Paper-Scissors Game** .2 ###

.Play a quick game against the computer

python```

Import random

Choices = ["rock", "paper", "scissors"]

)(Player = input("Choose rock, paper, or scissors: ").lower

Computer = random.choice(choices)

Print(f"Computer chose: {computer}")


:If player == computer

Print("It's a tie!")

\ Elif (player == "rock" and computer == "scissors") or

\ or )"player == "paper" and computer == "rock (

:)"player == "scissors" and computer == "paper (

Print("You win!")

:Else

Print("You lose!")

```

**Prime Number Checker** .3 ###

.Determines if a number Is prime

python```

Num = int(input("Enter a number: "))

:If num > 1

:For I in range(2, Int(num ** 0.5) + 1)

:If num % I == 0

Print(f"{num} Is not prime.")

Break

:Else

Print(f"{num} Is prime.")

:Else

Print("Enter a number greater than 1.")

```
**Random Password Generator** .4 ###

.Generates a strong password

python```

Import random

Import string

Length = int(input("Enter desired password length: "))

Characters = string.ascii_letters + string.digits + string.punctuation

Password = ''.join(random.choice(characters) for _ in range(length))

Print(f"Generated password: {password}")

```

**Simple To-Do List App (Console-based)** .5 ###

.Keeps track of tasks

python```

][ = Tasks

:While True

)(Action = input("\nChoose: (a)dd, (v)iew, (d)elete, (q)uit: ").lower

:'If action == 'a

Task = input("Enter a new task: ")

Tasks.append(task)

Print("Task added.")

:'Elif action == 'v

Print("\nYour tasks:")

:For I, t in enumerate(tasks, 1)
Print(f"{i}. {t}")

:'Elif action == 'd

Num = int(input("Enter task number to delete: "))

:If 1 <= num <= len(tasks)

Tasks.pop(num – 1)

Print("Task deleted.")

:Else

Print("Invalid task number.")

:'Elif action == 'q

Break

:Else

Print("Invalid option.")

```

Looking for something specific like machine learning, data


!visualization, or APIs? I can provide targeted examples

You might also like