1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
34kurt
3 years ago
10

Write a program that rolls two dice until the user gets snake eyes. You should use a loop and a half to do this. Each round you

should roll two dice (Hint: use the randint function!), and print out their values. If the values on both dice are 1, then it is called snake eyes, and you should break out of the loop. You should also use a variable to keep track of how many rolls it takes to get snake eyes.
Sample Run:

Rolled: 6 5
Rolled: 5 2
Rolled: 3 6
Rolled: 6 2
Rolled: 1 2
Rolled: 5 3
Rolled: 1 4
Rolled: 1 1
It took you 8 rolls to get snake eyes.

I have most of the code but when it prints it say you rolled 0 times every time.
import random

# Enter your code here

num_rolls = 0


import random
# Enter your code here

while True:

roll_one = random.randint(1,6)
roll_two = random.randint(1,6)
print ("Rolled: " +str(roll_one) +"," + str(roll_two))
if (roll_one == 1 and roll_two == 1):
print ("it took you " + str(num_rolls) + " rolls")
break

output:
Rolled: 3,5
Rolled: 6,4
Rolled: 2,4
Rolled: 3,6
Rolled: 5,2
Rolled: 1,1
it took you 0 rolls

suppose to say:
It took you (however many rolls) not 0
Computers and Technology
1 answer:
marishachu [46]3 years ago
4 0

import random

num_rolls = 0

while True:

   r1 = random.randint(1, 6)

   r2 = random.randint(1, 6)

   print("Rolled: " + str(r1) + "," + str(r2))

   num_rolls += 1

   if r1 == r2 == 1:

       break

print("It took you "+str(num_rolls)+" rolls")

I added the working code. You don't appear to be adding to num_rolls at all. I wrote my code in python 3.8. I hope this helps.

You might be interested in
Which of the following would be the most appropriate way to define a method that calculates and returns the final price, after t
Oksanka [162]

D. I hope it helped
5 0
2 years ago
The main reason to set a field size in access is to:
Nadya [2.5K]
The main reason to set a field size in access is to limit the lengths of value in the table.
Field size determines the limits or determines the maximum of text that can be input in the text or number field. Also, it may reduce data entry errors in changing the field size in access.
4 0
3 years ago
Some problems are better solved by a computer and some are better solved by humans.
aalyn [17]

Answer:

I say when u don't know the answer completly.

3 0
2 years ago
What is a database in access
aliya0001 [1]
Microsoft Access is a database management system (DBMS) from Microsoft that combines the relational Microsoft Jet Database Engine with a graphical user interface and software-development tools. ... It can also import or link directly to data stored in other applications and databases.
6 0
3 years ago
Define a class called TreeNode containing three data fields: element, left and right. The element is a generic type. Create cons
m_a_m_a [10]

Answer:

See explaination

Explanation:

// Class for BinarySearchTreeNode

class TreeNode

{

// To store key value

public int key;

// To point to left child

public TreeNode left;

// To point to right child

public TreeNode right;

// Default constructor to initialize instance variables

public TreeNode(int key)

{

this.key = key;

left = null;

right = null;

key = 0;

}// End of default constructor

}// End of class

// Defines a class to crate binary tree

class BinaryTree

{

// Creates root node

TreeNode root;

int numberElement;

// Default constructor to initialize root

public BinaryTree()

{

this.root = null;

numberElement = 0;

}// End of default constructor

// Method to insert key

public void insert(int key)

{

// Creates a node using parameterized constructor

TreeNode newNode = new TreeNode(key);

numberElement++;

// Checks if root is null then this node is the first node

if(root == null)

{

// root is pointing to new node

root = newNode;

return;

}// End of if condition

// Otherwise at least one node available

// Declares current node points to root

TreeNode currentNode = root;

// Declares parent node assigns null

TreeNode parentNode = null;

// Loops till node inserted

while(true)

{

// Parent node points to current node

parentNode = currentNode;

// Checks if parameter key is less than the current node key

if(key < currentNode.key)

{

// Current node points to current node left

currentNode = currentNode.left;

// Checks if current node is null

if(currentNode == null)

{

// Parent node left points to new node

parentNode.left = newNode;

return;

}// End of inner if condition

}// End of outer if condition

// Otherwise parameter key is greater than the current node key

else

{

// Current node points to current node right

currentNode = currentNode.right;

// Checks if current node is null

if(currentNode == null)

{

// Parent node right points to new node

parentNode.right = newNode;

return;

}// End of inner if condition

}// End of outer if condition

}// End of while

}// End of method

// Method to check tree is balanced or not

private int checkBalance(TreeNode currentNode)

{

// Checks if current node is null then return 0 for balanced

if (currentNode == null)

return 0;

// Recursively calls the method with left child and

// stores the return value as height of left sub tree

int leftSubtreeHeight = checkBalance(currentNode.left);

// Checks if left sub tree height is -1 then return -1

// for not balanced

if (leftSubtreeHeight == -1)

return -1;

// Recursively calls the method with right child and

// stores the return value as height of right sub tree

int rightSubtreeHeight = checkBalance(currentNode.right);

// Checks if right sub tree height is -1 then return -1

// for not balanced

if (rightSubtreeHeight == -1) return -1;

// Checks if left and right sub tree difference is greater than 1

// then return -1 for not balanced

if (Math.abs(leftSubtreeHeight - rightSubtreeHeight) > 1)

return -1;

// Returns the maximum value of left and right subtree plus one

return (Math.max(leftSubtreeHeight, rightSubtreeHeight) + 1);

}// End of method

// Method to calls the check balance method

// returns false for not balanced if check balance method returns -1

// otherwise return true for balanced

public boolean balanceCheck()

{

// Calls the method to check balance

// Returns false for not balanced if method returns -1

if (checkBalance(root) == -1)

return false;

// Otherwise returns true

return true;

}//End of method

// Method for In Order traversal

public void inorder()

{

inorder(root);

}//End of method

// Method for In Order traversal recursively

private void inorder(TreeNode root)

{

// Checks if root is not null

if (root != null)

{

// Recursively calls the method with left child

inorder(root.left);

// Displays current node value

System.out.print(root.key + " ");

// Recursively calls the method with right child

inorder(root.right);

}// End of if condition

}// End of method

}// End of class BinaryTree

// Driver class definition

class BalancedBinaryTreeCheck

{

// main method definition

public static void main(String args[])

{

// Creates an object of class BinaryTree

BinaryTree treeOne = new BinaryTree();

// Calls the method to insert node

treeOne.insert(1);

treeOne.insert(2);

treeOne.insert(3);

treeOne.insert(4);

treeOne.insert(5);

treeOne.insert(8);

// Calls the method to display in order traversal

System.out.print("\n In order traversal of Tree One: ");

treeOne.inorder();

if (treeOne.balanceCheck())

System.out.println("\n Tree One is balanced");

else

System.out.println("\n Tree One is not balanced");

BinaryTree

BinaryTree treeTwo = new BinaryTree();

treeTwo.insert(10);

treeTwo.insert(18);

treeTwo.insert(8);

treeTwo.insert(14);

treeTwo.insert(25);

treeTwo.insert(9);

treeTwo.insert(5);

System.out.print("\n\n In order traversal of Tree Two: ");

treeTwo.inorder();

if (treeTwo.balanceCheck())

System.out.println("\n Tree Two is balanced");

else

System.out.println("\n Tree Two is not balanced");

}// End of main method

}// End of driver class

5 0
3 years ago
Other questions:
  • What can you look for on a website to indicate that the information it presents is reliable?
    15·1 answer
  • When information about a person remains on the internet indefinitely it is known as?
    6·1 answer
  • (Game Design) Which of the following is NOT a name of a popular digital sculpting application?
    13·1 answer
  • You can use RWA to demonstrate how to do something special on the web, such as displaying articles found on websites that suppor
    15·1 answer
  • To edit the color of the text in presentation software, choose the Font color command Text Color in the ________ ribbon toolbar.
    15·2 answers
  • Within a major students can choose to study a specific area within major. For example a journalism student may study military jo
    8·1 answer
  • Please as soon as possible
    13·1 answer
  • What are other ways you could use the shake or compass code blocks in physical computing projects?
    14·1 answer
  • Nicole is in a study group to prepare for a test on plant biology, a subject she knows a lot about. During their meetings, she a
    8·2 answers
  • Type the correct answer in the box. Spell all words correctly.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!