CodeSolved

Solved Programming Questions & Exercises

Dice

Practice Easy 73/ Download 2539 Views

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

12 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.
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))
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
x = random.randint(1,6)
while True:
    y = input("for end & start program press (s/d):")
    if y == 'd' :
        print("....end....")
        break
    elif y == 's' :

        while True:
            if x == 1:
                print(" |       |",'\n',"|   o   |",'\n',"|       |")
            elif x == 2:
                print(" |o      |",'\n',"|       |",'\n',"|      o|")
            elif x == 3:
                print(" |o      |",'\n',"|   o   |",'\n',"|      o|")
            elif x == 4:
                print(" |o     o|",'\n',"|       |",'\n',"|o     o|")
            elif x == 5:
                print(" |o     o|",'\n',"|   o   |",'\n',"|o     o|")
            elif x == 6 :
                print(" |o     o|",'\n',"|o     o|",'\n',"|o     o|")
            break
    else :
        print("Invalid input. Please choose 's' or 'd'.")
Ali.r.h.z Download Python
from random import *
a=randrange(1,7)
print('your number is',a)
Hamedfari Download Python
user_won=0
computer_won=0

while True :
    user=input('ba (space) tas mindazi zaa ba q az bazi kharej mishi:').lower()
    import random
    user_pick=random.randint(1,6)
    computer_pick=random.randint(1,6)
    if (user=='q'):break
    if(user_pick>computer_pick):
        user_won +=1        
    else:
        computer_won +=1
    print('you',user_pick)
    print('computer',computer_pick)
print('you won',user_won)
print('computer won',computer_won)
input('ba man kari nadari:')
Omid.asadi Download Python
<< Previous page 1 2 Next page >>

Submit answer

Submitting answers is currently unavailable.

Related content

Detection using AI
×
×
Close