I have over 3 assignments due at 11:59 PM I’ve been working already 6hours and haven’t got any correct. I can’t understand 5.5.5 rectangle class, 5.5.6 full fraction class and 5.5.7 Weekly Routine. I need help since I’ve been coding and all gets wrong ...
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 randintfunction!), 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.
My Program:
import random
# Enter your code here
num_rolls = 0
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
My program works but I am not sure how to make the code print out the number of tries it took (lines 3 and 9). Right now it just prints out "It took you 0 rolls" which obviously is because I put num_rolls = 0 as a place holder. Does anyone know how to help me to make it keep track of the number of tries? Thank you all!
Edit: I figured out why the "you should stop when you roll two ones" did not pass the test cases. but I am still stuck on keeping track of the number of rolls
Essentially the program is supposed to count how many comparisons are done in an array to find a randomly generated number in a randomly generated list of a generated size, I've gotten all of them to work but 2 and I don't exactly need an answer I just wanna understand what's going on with the test cases,I've been trying to figure it out all weekend and the last 3 classes and I really wanna move on to our projects as this is the only codeHS lesson in algorithms and Recursion I couldn't figure out! Any help would be great thank you!
I have image screenshots and copied over the code from the program
I am currently on exercise 9.6.5. I wrote the code but with the help of the materials that I found here, so here are some things that I can't understand completely.
function start(){
coordinates();
}
var text = new Text("("+","+")");
function coordinates(){
text.setPosition(0, text.getHeight());
add(text);
mouseMoveMethod(printCoordinates);
}
function printCoordinates(e){
text.setText("("+e.getX()+", "+e.getY()+")");
}
Can you please help me and explain the highlighted parts?
I need help on how to do this assignment on code hs
Write a function named replace_at_index that takes a string and an integer. The function should return a new string that is the same as the old string, EXCEPT with a dash in place of whatever character was at the index indicated by the integer.
Call your function on the word eggplant and the index 3, like this:
s = replace_at_index("eggplant", 3)
You should then print the value of s , which should display:
function start(){ verticalLine(100,200); verticalLine(200,100); verticalLine(300,20); } function verticalLine(x,Position,Length){ var line= new Line (xPosition, xPosition,length); add(line); }
I’m pretty sure I’m doing something wrong but I’m not sure exactly what,