# Python Exercises (Begineers)

**A) Write a program to check your age if you are eligible to vote or not. (age must be equal or greater than 18)**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703219285453/2b009919-0689-4fa3-9f7b-4179a28e7079.png align="left")

\-

**B) Write a program to separate the username and the domain parts from the provided email. \[eg.** [**sujan@gmail.com**](mailto:sujan@gmail.com)**, username = sujan domain =** [**gmail.com**](http://gmail.com)**\]**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703221561117/222feab3-a364-48cf-ba2b-d2212089d6c7.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703221636265/600fae8d-e359-4718-9519-d5a1397e2979.png align="center")

\-

**C) Write a program to make a digital timer.**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703240492384/24c31b18-d263-4cc5-9ecb-032f171f78f5.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703240506534/4e345bc4-e9f9-4e2e-94f5-67c983000032.png align="center")

\-

**D) Write a program to make a simple shopping cart.**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703239610096/bd71b5d0-17af-43e9-ad7b-a73f90c35740.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703239621576/3500a5ef-708a-431d-948a-efb6b96f359e.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703239594287/b13f9af8-08ec-4706-b2ba-419538f628c8.png align="center")

\-

**E) Write a program to make a num pad (image for demo)**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703242224606/237bfa96-77d2-49f9-bcba-db2a15c4ce80.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703242616731/4242c0f7-a284-4c81-9a17-dcce30e82583.png align="left")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703242633113/cbd55ab7-c44a-4f36-a40c-676ee324977f.png align="left")

\-

**F) Write a program to make a concession stand**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703390010025/d3926f78-a796-43f2-87a4-c1ced134906e.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703390041220/df8684e4-6f0e-4e93-9330-5b5a81b46ef1.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703390069256/b4176d64-94df-44de-9f3e-b1581e10780a.png align="center")

**\-**

**G) Write a number guessing game in python.**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703466739597/6f43641a-952c-499c-863f-341e3a88a9eb.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703466752335/22539d94-97b0-48d8-9557-a1eeb110070d.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703466771423/3b9b399f-6a90-493f-9f5e-4f29f322123b.png align="center")

\-

**H) Rock, Paper, Scissor game**

```python
# Rock Paper Scissors game in python
import random

options = ("rock", "paper", "scissors")
playAgain = True

while playAgain:
    player = None
    computer = random.choice(options)

    while player not in options:
        player = input("Enter your choice 'rock', 'paper' or 'scissors': ")

        print(f"Player: {player}")
        print(f"Computer: {computer}")

        if player == computer:
            print("It's a tie")
        # The or \ is a way of continuing a line of code onto the next line in Python.
        elif (player == "rock" and computer == "scissors") or \
                 (player == "paper" and computer == "rock") or \
                 (player == "scissors" and computer == "paper"):
            print("You win")
        else:
            print("You lose")

    conti = input("Wanna play again? (y/n): ")
    while conti != 'y' and conti != 'n':
        print("Invalid entry, enter y/n:")
        conti = input("Wanna play again? (y/n): ")
        if conti == 'n':
            playAgain = False
            break
        elif conti == 'y':
            computer = random.choice(options)
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703481312022/2e51b351-fcb6-4d9d-8e48-ac75468f96fb.png align="center")

**\-**

**I) Simple encryption program in python**

```python
# Encryption program in python
import random
import string

chars = " " + string.punctuation + string.digits + string.ascii_letters
chars = list(chars) #chars is typecasted into list

keys = chars.copy()
random.shuffle(keys)

# Encryption
msg = input("Enter message to encrypt: ")
cipher_text = ""
for letter in msg:
    index_ = chars.index(letter)
    cipher_text += keys[index_]

print(f"Text encoded: {cipher_text}")

#Decryption
original_msg = ""
cipher = input("Enter the cipher text to decode: ")
for item in cipher:
    ind_ = keys.index(item)
    original_msg += chars[ind_]
print(f"Original message: {original_msg}")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703498117267/bb210071-5531-410d-ae4a-fc05192539a8.png align="center")
