import random
count = 0
while True:
dice = random.randint(1,6)
print(dice)
count += 1
if dice == 6:
break
print('You got 6!')
print('You rolled',count,'times')
#Python
xxxxxxxxxx
let dice;
let count = 0;
do {
dice = Math.ceil(Math.random()*6);
console.log(dice);
count += 1;
} while (dice != 6);
console.log('You got 6!');
console.log('You rolled',count,'times');
//JavaScript
public class Main {
public static void main(String[] args) {
java.util.Random random = new java.util.Random();
int dice;
int count = 0;
dice = random.nextInt(6) + 1;
System.out.println(dice);
count++;
System.out.println("You got 6!");
System.out.println("You rolled " + count + " times");
}
//Java
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;
int main() {
srand(time(nullptr));
dice = rand() % 6 + 1;
cout << to_string(dice) + "\n";
cout << "You got 6!\n";
cout << "You rolled " + to_string(count) + " times\n";
return 0;
//C++