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

5

The document presents five Python code examples, including a Dice Roller Simulator, a Simple Stop Watch, a Currency Converter, a filter for Even Numbers in a List, and a Simple Hangman Game. Each example demonstrates different functionalities, such as simulating dice rolls, tracking time, converting currencies, filtering even numbers, and implementing a word-guessing game. The document invites readers to request additional examples involving graphics, web development, or AI.

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)
8 views4 pages

5

The document presents five Python code examples, including a Dice Roller Simulator, a Simple Stop Watch, a Currency Converter, a filter for Even Numbers in a List, and a Simple Hangman Game. Each example demonstrates different functionalities, such as simulating dice rolls, tracking time, converting currencies, filtering even numbers, and implementing a word-guessing game. The document invites readers to request additional examples involving graphics, web development, or AI.

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 new Python code examples**, each offering

:something different and interesting

**Dice Roller Simulator** .1 ###

.Simulates rolling two dice

python```

Import random

Dice1 = random.randint(1, 6)

Dice2 = random.randint(1, 6)

Print(f"You rolled: {dice1} and {dice2}")

Print(f"Total: {dice1 + dice2}")

```

**Simple Stop Watch** .2 ###

.Tracks elapsed time between start and stop

python```

Import time

Input("Press Enter to start the stopwatch…")

)(Start = time.time

Input("Press Enter to stop the stopwatch.")

)(End = time.time

Print(f"Elapsed time: {end - start:.2f} seconds")

```
**Currency Converter (USD ↔ EUR)** .3 ###

.Converts between US Dollars and Euros (example with static rate)

python```

Rate = 0.85 # Example: 1 USD = 0.85 EUR

Amount = float(input("Enter amount: "))

)(Currency = input("Convert from (USD/EUR): ").upper

:"If currency == "USD

Print(f"{amount} USD = {amount * rate:.2f} EUR")

:"Elif currency == "EUR

Print(f"{amount} EUR = {amount / rate:.2f} USD")

:Else

Print("Invalid currency.")

```

**Even Numbers in a List** .4 ###

.Filters out even numbers from a user-provided list

python```

Numbers = list(map(int, input("Enter numbers separated by spaces:


").split()))

Evens = [n for n In numbers if n % 2 == 0]

Print(f"Even numbers: {evens}")

```
**Simple Hangman Game** .5 ###

.A basic word-guessing game

python```

Import random

Words = ["python", "hangman", "challenge", "programming"]

Word = random.choice(words)

)(Guessed = set

Tries = 6

:While tries > 0 and set(word) - guessed

Display = [letter if letter in guessed else '_' for letter in word]

Print(" ".join(display))

)(Guess = input("Guess a letter: ").lower

:If guess in word

Guessed.add(guess)

:Else

Tries -= 1

Print(f"Wrong! Attempts left: {tries}")

:If set(word) – guessed

Print(f"You lost! The word was '{word}'.")

:Else

Print(f"Congratulations! You guessed the word '{word}'.")

```
Want examples with graphics, web development, or AI? Let me
!know

You might also like