CodeSolved

Solved Programming Questions & Exercises

Dice

Practice Easy 73/ Download 3048 Views

Write a program that, like a dice, prints a random number between 1 and 6 in the output with each time running

17 Answers

This answer is only visible to premium members
This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error'
alert(msg) 
This answer is only visible to premium members
This answer is only visible to premium members

This answer is only visible to premium members

Subscription is currently unavailable.
This answer is only visible to premium members
This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error'
alert(msg) 
This answer is only visible to premium members
This answer is only visible to premium members

This answer is only visible to premium members

Subscription is currently unavailable.
This answer is only visible to premium members
This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error'
alert(msg) 
This answer is only visible to premium members
This answer is only visible to premium members

This answer is only visible to premium members

Subscription is currently unavailable.
import random

def roll_dice():
    # Select a random number between 1 and 6
    dice_number = random.randint(1, 6)
    return dice_number

# The implementation of the function and printing the result
result = roll_dice()
print("تاس رول شده:", result)
Mma123 Download Python
import random

def roll_dice():
    print(random.randint(1, 6))

roll_dice()
Ai Download Python
import random
while True:
    a=input("Would you like to roll the dice: 1.Yes  2.No\n")
    if a=="2":
        print("End")
        break
    elif a=="1":
        print(random.randint(1,7))
        continue
Zaras Download Python

I used the generator for two reasons.
1. It is said to print a number with each time running.
2. The use of the generator is better in this example.

from random import randint
def dice():
    yield randint(1, 6)
dice_gen=dice()
print(next(dice_gen))
from random import choice
nums = list(range(1,7))
print(f"Tas number is: {choice(nums)} ")

Emrimo Download Python
public static void main(String[] args) {
        int RolDice = (int) (Math.random() * 6) + 1;
        if (RolDice == 1) {
            System.out.println("[      ]");
            System.out.println("[   0  ]");
            System.out.println("[      ]");
        }else if (RolDice == 2) {
            System.out.println("[0     ]");
            System.out.println("[      ]");
            System.out.println("[     0]");
        }else if (RolDice == 3) {
            System.out.println("[0      ]");
            System.out.println("[   0   ]");
            System.out.println("[      0]");
        }else if (RolDice == 4) {
            System.out.println("[0    0]");
            System.out.println("[      ]");
            System.out.println("[0    0]");
        }else if (RolDice == 5) {
            System.out.println("[0    0]");
            System.out.println("[   0  ]");
            System.out.println("[0    0]");
        }else if (RolDice == 6) {
            System.out.println("[0    0]");
            System.out.println("[0    0]");
            System.out.println("[0    0]");
        }
    }
Tahabx3 Download Java
import random
def tas():
    return random.randint(1,6)
print(tas())
Shina Download Python
<< Previous page 1 2 Next page >>

Submit answer

Submitting answers is currently unavailable.

×
×
Close