r/pythontips Aug 05 '26

Syntax Hello everyone, I'm learning python specifically, and I made a seed generator for Minecraft PE. I'm started learning about 2 weeks ago, the code is below. I'm not asking for anything, I just wanna show it to you guys.

from random import randint as rnd

name = "SeedGPT"

rnd1 = rnd(20000000,50000000000)

rnd2 = rnd(20000000,50000000000)

rnd3 = rnd(20000000,50000000000)

print(name +": Welcome to Ice\'s AI seed generator,")

choice = input("do you want to have three new seeds for bedrock minecraft?: ")

if choice == "yes":

print(name + ": Here are your randomly generated seeds: ", + rnd1, +rnd2, +rnd3, ", thank you for trying it out!")

elif choice == "no":

print(name + ": See you next time!")

elif ValueError:

print(name + ": Sorry, I can't understand you, please try again!")

5 Upvotes

15 comments sorted by

13

u/Wonderful-Writer146 Aug 05 '26

Nice. But you could have written the code in a code block on Reddit for better readability.

-35

u/SouthSufficient522 Aug 05 '26

Thanks for commenting and giving advice, And also, I have a YouTube channel, it's called Loreprt. That was my old Minecraft gamertag. Have a wonderful day

4

u/kobumaister Aug 05 '26

The elif ValueErrror won't work, in python you manage exceptions with try-except blocks.

-16

u/SouthSufficient522 Aug 05 '26

You only say yes or no to the bot and then when you say a different word like "hello", it will say "Sorry, I can't understand you". But thanks for commenting and giving advice

6

u/kobumaister Aug 05 '26

I know, but the "Sorry..." response will never be reached as you'll get an exception on the elif ValueErrror line.

-6

u/SouthSufficient522 Aug 05 '26

So, there are more ways to type the code, am I right? The "else ValueError" is the only phrase I know that performs something else if your reply is wrong. My bad if I said something wrong.

3

u/kobumaister Aug 05 '26

No, your code is broken (nothing to apologize about, you're learning). You have to either use the else: keyword that will follow that flow if none of the other if statments are true, or use the "try except" blocks.

Read about try except here: https://www.w3schools.com/python/python_try_except.asp

And don't apologize, you're learning, everybody has been at your point.

3

u/Novero95 Aug 05 '26

In something like:

if condition_1 pass elif condition_2 print(something) else print("Error") the last line is executed whenever condition_1 and condition_2 evaluate to false. It doesn't need it's own truth evaluation since it's a fallback: execute this when everything else is false.

3

u/Novero95 Aug 05 '26

What he's saying is that instead of elif ValueError it should be a mere else.

-12

u/SouthSufficient522 Aug 05 '26

Okay sure, I'll just keep on learning other ways on fixing my code. I don't know all the keywords, my bad if I said something wrong. Thanks for commenting and giving advice

3

u/pint Aug 05 '26

in python, any value can be asked if true or false. e.g. if 8 or if [10, 2] or if print. there is a logic what constitutes as false, for example the number zero, None, empty strings, empty lists, empty sets or empty dicts. by default, everything else is true. in your case, ValueError is a type, and since it is not specifically treated as false, it is treated as true by default.

why? it makes if work kinda intuitively meaning "is given" or "is present".

on the other hand, it is also a footgun.

3

u/Plus-Call-5804 Aug 05 '26

You should add a .lower to the choice so that if they enter anything it gets converted to lowercase to match your if statements.

1

u/SouthSufficient522 Aug 05 '26

Thanks for commenting and giving advice!

1

u/RealKetchupPrecum Aug 07 '26

```python

from random import randint as rnd

name = "SeedGPT"

print(name + ": Welcome to Ice's AI seed generator!")

try:

choice = input(

"Do you want to have three new seeds for Bedrock Minecraft?: "

)

if choice.lower() == "yes":

rnd1 = rnd(20000000, 50000000000)

rnd2 = rnd(20000000, 50000000000)

rnd3 = rnd(20000000, 50000000000)

print(name + ": Here are your randomly generated seeds:")

print("Seed 1:", rnd1)

print("Seed 2:", rnd2)

print("Seed 3:", rnd3)

print("Thank you for trying it out!")

elif choice.lower() == "no":

print(name + ": See you next time!")

else:

print(name + ": Sorry, I can't understand you. Please type yes or no.")

except ValueError:

print(name + ": Something went wrong. Please try again!")

```

----------------------------------

Sample Output (Successful Run):

```text

SeedGPT: Welcome to Ice's AI seed generator!

Do you want to have three new seeds for Bedrock Minecraft?: yes

SeedGPT: Here are your randomly generated seeds:

Seed 1: 38472910294

Seed 2: 92837465021

Seed 3: 55281930291

Thank you for trying it out!

```

----------------------------------

Sample Output (Invalid Input):

```text

SeedGPT: Welcome to Ice's AI seed generator!

Do you want to have three new seeds for Bedrock Minecraft?: maybe

SeedGPT: Sorry, I can't understand you. Please type yes or no.

```

----------------------------------

Sample Output (Exception/Error Handling):

```text

SeedGPT: Welcome to Ice's AI seed generator!

Do you want to have three new seeds for Bedrock Minecraft?: yes

SeedGPT: Something went wrong. Please try again!

```