Coding Practice¶
The
Test1
program should generate a random number and print if it is evenly divisible by 2. However, the code has an error and always prints “Your number is even”, even if the random number is odd. Fix the code so that it only prints the message when the number is even.The
Test2
program should check your guess against the answer and print that it is too low, correct, or too high. However, the code has errors. Fix the code so that it compiles and runs correctly.The
Test3
program should print “You can go out” if you have done your homework and cleaned your room. However, the code has errors. Fix the code so that it compiles and runs correctly.The
Test4
program should print if x is in the range of 0 to 10 (including 0 and 10). However, the code has errors. Fix the errors so that the code runs as intended.The
Test5
program should print if x is less than 0, equal to 0, or greater than 0. Finish it to work correctly.Finish the
Test6
program so that it printsYou can go out
if you have a ride or if you can walk and otherwise printsYou can't go out
. Use a logical or to create a complex conditional.Finish the
Test7
program to print you can go out if you don’t have homework and you have done the dishes.Finish the
Test8
program so that it printsYou have a fever
if your temperature is above 100 and otherwise printsYou don't have a fever
.Finish the
Test9
program to printIt is freezing
if the temperature is below 30,It is cold
if it is below 50,It is nice out
if it is below 90, orIt is hot
using nested if else statements.Rewrite the
Loop1
program to use awhile
loop instead of afor
loop to print out the numbers from 1 to 10 (inclusive).Rewrite the
Loop2
program so that it uses afor
loop instead of awhile
loop to print out all the integers from 5 to 15 (inclusive).Rewrite the
Loop3
program to use awhile
loop instead of afor
loop to print out the numbers from 10 to 100 by 10’s (inclusive).The
Loop4
program should print the values from 1 to 10 (inclusive) but has errors. Fix the errors so that the code works as intended. If the code is in an infinite loop you can refresh the page in the browser to stop the loop and then click on Load History and move the bar above it to see your last changes.The
Loop5
program should print the values from 10 to 5, but it has errors. Fix the errors so that the code works as intended.The
Loop6
program should print the values from 10 to 1, but it has errors. Fix the errors so that the code works as intended.Finish
Loop7
program to print a countdown from 100 to 0 by 10’s using a for or while loop.Finish the
Loop8
program to print the value ofx
and" is even"
ifx
is even and" is odd"
if it is odd for all values from 10 to 1.Finish the
Loop9
program to print the values for10 * x
wherex
changes from 0 to 10 using a loop.Finish the
Loop10
program so that it prints a string message minus the last character each time through the loop until there are no more characters in message. The loop condition should test the length of the message. The loop body should print the message and then use substring to create a new message without the last character.Finish
Loop11
program to loop printing the message each time through the loop and remove anx
from the message until all thex
’s are gone.Write a loop in the
Loop12
program to print the number ofx
’s in the string message. Use theindexOf
andsubstring
methods.Write the
Loop13
program to print a rectangle of stars (*
) with 5 rows of stars and 3 stars per row. Hint: use nested for loops.Write the
Loop14
program to print a rectangle of stars (*
) with 3 rows of stars and 5 stars per row.Write the
Loop15
program to print 55555, 4444, 333, 22, 1 with each on a different line.