DICE ROLLER program in Python ⚂

Sdílet
Vložit
  • čas přidán 15. 11. 2022
  • #python #tutorial #course
    Here are the Unicode characters I use for drawing the dice.
    CZcams has strange spacing, so the ASCII art looks warped in the description.
    It should still work if you copy and paste it into PyCharm.
    ● ┌ ─ ┐ │ └ ┘
    import random
    dice_art = {
    1: ("┌─────────┐",
    "│ │",
    "│ ● │",
    "│ │",
    "└─────────┘"),
    2: ("┌─────────┐",
    "│ ● │",
    "│ │",
    "│ ● │",
    "└─────────┘"),
    3: ("┌─────────┐",
    "│ ● │",
    "│ ● │",
    "│ ● │",
    "└─────────┘"),
    4: ("┌─────────┐",
    "│ ● ● │",
    "│ │",
    "│ ● ● │",
    "└─────────┘"),
    5: ("┌─────────┐",
    "│ ● ● │",
    "│ ● │",
    "│ ● ● │",
    "└─────────┘"),
    6: ("┌─────────┐",
    "│ ● ● │",
    "│ ● ● │",
    "│ ● ● │",
    "└─────────┘")
    }
    dice = []
    total = 0
    num_of_dice = int(input("How many dice?: "))
    for die in range(num_of_dice):
    dice.append(random.randint(1, 6))
    PRINT VERTICALLY
    for die in range(num_of_dice):
    for line in dice_art.get(dice[die]):
    print(line)
    PRINT HORIZONTALLY
    for line in range(5):
    for die in dice:
    print(dice_art.get(die)[line], end="")
    print()
    for die in dice:
    total += die
    print(f"total: {total}")

Komentáře • 77

  • @BroCodez
    @BroCodez  Před rokem +32

    # Here are the Unicode characters I use for drawing the dice.
    # CZcams has strange spacing, so the ASCII art looks warped in the description.
    # It should still work if you copy and paste it into PyCharm.
    # ● ┌ ─ ┐ │ └ ┘
    import random
    dice_art = {
    1: ("┌─────────┐",
    "│ │",
    "│ ● │",
    "│ │",
    "└─────────┘"),
    2: ("┌─────────┐",
    "│ ● │",
    "│ │",
    "│ ● │",
    "└─────────┘"),
    3: ("┌─────────┐",
    "│ ● │",
    "│ ● │",
    "│ ● │",
    "└─────────┘"),
    4: ("┌─────────┐",
    "│ ● ● │",
    "│ │",
    "│ ● ● │",
    "└─────────┘"),
    5: ("┌─────────┐",
    "│ ● ● │",
    "│ ● │",
    "│ ● ● │",
    "└─────────┘"),
    6: ("┌─────────┐",
    "│ ● ● │",
    "│ ● ● │",
    "│ ● ● │",
    "└─────────┘")
    }
    dice = []
    total = 0
    num_of_dice = int(input("How many dice?: "))
    for die in range(num_of_dice):
    dice.append(random.randint(1, 6))
    # PRINT VERTICALLY
    # for die in range(num_of_dice):
    # for line in dice_art.get(dice[die]):
    # print(line)
    # PRINT HORIZONTALLY
    for line in range(5):
    for die in dice:
    print(dice_art.get(die)[line], end="")
    print()
    for die in dice:
    total += die
    print(f"total: {total}")

  • @CodeEnthusiast78912
    @CodeEnthusiast78912 Před rokem +20

    keep doing what you are doing, you are a hero to this community, even though i'm not interested in python rn, i'm so happy when i see you post anything.

  • @user-vc3tp8zj5s
    @user-vc3tp8zj5s Před rokem +4

    horizontal print was blowing my mind after days without good sleep. i had to check everything by myself in pycharm and now i understand
    ty for great vid bro.

  • @thegeoman
    @thegeoman Před 6 měsíci

    idk why but this in particular just feels so cool to do!

  • @estelle9819
    @estelle9819 Před rokem

    amazing explanation of the code! tysm

  • @elevendarter112
    @elevendarter112 Před rokem +4

    Great lesson in 10 minutes! Other youtubers would divide it into three tutorials, 30 minutes each...
    It's so easy if you know the logic behind it. Basically it's just a few simple steps, nothing new for me. However, I'd never be able to arrange these steps into this program myself. At least it would take me more than a few days, especially finding the way you printed all dice in one row.
    What's more, english isn't my native language and I've just found out that a die is a singular form of dice . And dice is plural. Cool, I learned something new in two languages at the same time :-)))

    • @mo-ab7315
      @mo-ab7315 Před 10 měsíci

      cough cough mr corey

  • @Thesahilpurkaitmusic
    @Thesahilpurkaitmusic Před rokem

    YAy bro im learning from your videos and other resources both really helpful

  • @lirimbytyqi1
    @lirimbytyqi1 Před rokem

    Great program! Thanks!

  • @jmm1233
    @jmm1233 Před 8 měsíci

    awesome little project for a dnd session

  • @theblackdragon7321
    @theblackdragon7321 Před rokem +2

    I wonder if there is a better way to do the dice since the bottom and the top are the same for each dice. I know this is a small program in the scheme of things, but always interesting to see what can be improved upon. Thank you for all these vids that you do

    • @cubopez743
      @cubopez743 Před rokem +2

      your dictionary could only consist of the middle 3 rows and just print the top and bottom part of the dice placing the actual dice choice in between. As for optimization idk how much faster or better memory related it would be, probably not much if at all.

  • @thedeparted_one
    @thedeparted_one Před rokem

    Bro is so awesome! Thanks.

  • @aliashou7488
    @aliashou7488 Před rokem

    thanks Bro! loved this video!👍

  • @tripphouse8165
    @tripphouse8165 Před rokem

    thanks Bro! loved this video!

  • @codingworld-programmerslif430

    amazing stuff.

  • @_Default.
    @_Default. Před rokem

    Can you please make a tutorial on how to make a “Key input” code like when you enter the correct key in the input it sends a console log

  • @Mizu2023
    @Mizu2023 Před rokem +14

    Almost read the big text in the thumbnail as "Rick Roller Program" LMAO

  • @Beauchant
    @Beauchant Před rokem

    Oh wow, very nice Bro.

  • @muhammadsami4002
    @muhammadsami4002 Před rokem

    Great Channel and Great Work, to easy to understand

    • @Demboys_p
      @Demboys_p Před rokem

      how do u find python so far .

  • @adekunleoyero6174
    @adekunleoyero6174 Před 8 měsíci +1

    the "this is an abomination" got me

  • @tee-hee9553
    @tee-hee9553 Před rokem

    Wow so cool

  • @azaanahmed9562
    @azaanahmed9562 Před rokem

    I love this

  • @SEBAS31077
    @SEBAS31077 Před rokem

    wow amazing

  • @innocent_star408
    @innocent_star408 Před rokem +2

    Make some java project ❤️‍🔥🤙🏻
    (Java builder window and net beans )both are same function ha..need to know bro✌🏻..

  • @dezaku6612
    @dezaku6612 Před rokem

    Ever thought of making a Go course? I think there is actually a lot of people interested

  • @soumoroy6747
    @soumoroy6747 Před 6 měsíci

    cool bro

  • @anonymoususer1681
    @anonymoususer1681 Před rokem

    Would it be possible to get a Cpp version?

  • @YouGotCAGEDyt
    @YouGotCAGEDyt Před rokem

    Thank you bro

  • @kubuzeer6510
    @kubuzeer6510 Před rokem

    could you please make Entity Relationship Diagram video for mySQL? c:

  • @ronaldcruz625
    @ronaldcruz625 Před rokem

    PLEASE HELP ME! Is there anyone who have the source code of 'pseudo-random numbers' video that are formerly included in this series of videos?

  • @innocent_star408
    @innocent_star408 Před rokem +1

    Window builder jframe and by own make some function jframe both are same functionality... Explain windows builder function about

  • @icodeint2780
    @icodeint2780 Před 8 měsíci

    Needed that for a yahtzee games for python

  • @arusharamessur6856
    @arusharamessur6856 Před rokem

    Hello, can you dobthe same dice roll game in c language, with the dice art please

  • @bluebraintech4168
    @bluebraintech4168 Před rokem +1

    thank you bro , god bless you , I'am muslim.

  • @rubenmatton6258
    @rubenmatton6258 Před rokem

    Wow

  • @kristijanlazarev
    @kristijanlazarev Před 5 měsíci

    n0ice

  • @sunilbarman6364
    @sunilbarman6364 Před 10 měsíci

    Hey, I was trying this code in vscode but some error is occurring. Does your code works in pycharm only that's why it might not be running in vscode or is there any other fault?

    • @user-hd8qh8lp6m
      @user-hd8qh8lp6m Před 8 měsíci

      it runs in VScode, just have to download the python extension in the 'extensions' tab. Make sure to refresh and then it should work. Just did it on there.

  • @arvinmistry9744
    @arvinmistry9744 Před rokem

    Cannot see your typing in black colouer qback ground

  • @user-zk1mh8gw7w
    @user-zk1mh8gw7w Před 2 měsíci

    pov: you just copy and pasted the coment he game on to python AND IT WORKED

  • @user-vd9wf3hn5m
    @user-vd9wf3hn5m Před 11 měsíci

    THANK YOUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU

  • @brhoom.h
    @brhoom.h Před rokem

    I have a question : why you in the dictionary you put a tuple in the value?
    You can put a list... so is there any reason that make you decide to make it in tuple?

    • @thedeparted_one
      @thedeparted_one Před rokem +3

      Tuples may be a bit faster, I think. Also, you don't want the values to change.

    • @brhoom.h
      @brhoom.h Před rokem

      @@thedeparted_one Thank you

  • @ROHAN-tp7rf
    @ROHAN-tp7rf Před rokem +3

    Sir Can You make video on Full process of App development, such as:-
    Which language is use to make Android / iOS app?
    In which software we will code this?
    How to make online games??
    🙏🙏🙏🙏

  • @lalamlavakumar1248
    @lalamlavakumar1248 Před 8 měsíci

    How to predict next number in game

  • @drmicho1595
    @drmicho1595 Před 24 dny

    Why the range is 5
    The computer starts with 0 right?

  • @aijazbirsfun547
    @aijazbirsfun547 Před 2 měsíci +1

    Radhe Radhe
    Sanatan Hi Satya Hai
    Jai To All Gods & Godesses
    Jai Baba Farid Ji
    Radhaswami Ji

  • @kinzo9636
    @kinzo9636 Před rokem

    is the dictonary in Python an equvilant to switch case in Java ?

    • @paraglide01
      @paraglide01 Před rokem +1

      yes

    • @MechanicusOfficial
      @MechanicusOfficial Před 3 měsíci

      No. The equivalent of switch in python is match instead of switch. And no break. A dictionary is a hashmap in Java.

  • @mdfaisalmahamud
    @mdfaisalmahamud Před rokem

    Javascript project video upload please

  • @JorgeLuis-ts6qp
    @JorgeLuis-ts6qp Před rokem

    I think beginners should learn the built in sum function instead of implementing their own sum loop.

  • @rayforever
    @rayforever Před rokem

    Good good
    now make call of duty console version

  • @mohammedisarezwani
    @mohammedisarezwani Před 10 měsíci +1

    😵‍💫😵‍💫😵‍💫😵‍💫

  • @soumoroy6747
    @soumoroy6747 Před 6 měsíci

    you are my new brother bro roy

  • @bagman23
    @bagman23 Před rokem

    first :)

  • @hamzazad5258
    @hamzazad5258 Před 4 měsíci

    this one is hard ngl

  • @meenakshichoudhary7164
    @meenakshichoudhary7164 Před 6 měsíci

    num_dices=2
    for num in range(num_dices):
    comp_num=random.randint(1,6)
    print(comp_num)
    for i in range(5):
    print(dice_art[comp_num][i])
    here's my code, I tried it in another way.

  • @dshadick
    @dshadick Před rokem

    Greet me bro,,,

  • @Aillmi
    @Aillmi Před měsícem

    print("\u25CF \u250C \u2500 \u2510 \u2502 \u2514 \u2518")

  • @avdhoot3749
    @avdhoot3749 Před rokem

    whattttttttttttttttttttttttttttttttttttt theeeeeeeeeeeeeeeeeeeeeeeeeee fvckkkkkkkkkkkkkkkkkkkkkkkk , i dont understand bro its complexxxxxxxxxxxxxxx

  • @ivopdimitrov
    @ivopdimitrov Před rokem

    Would be great if you post a link to GitHub repo