Answer:
import random
def grid_maker(x, y):
return [ [str(random.randint(-30, 30)) for _ in range(x)]for _ in range(y) ]
print ('\n'.join(' '.join(row) for row in grid_maker(4, 5)))
Explanation:
We use a template function and we generate numbers between -30 and 30:
>>> [str(random.randint(-30, 30))]
We also use the str() method so we can later concatenate the integers with \n. If you do not specify the integers, it will cause a crash. Also, keep in mind if we use a variable to store the integers, it will come out more of like a seed than a random grid. For instance, output without the random integers in a variable:
-12 16 -18 -3
7 5 7 10
18 -21 -16 29
21 3 -4 10
12 9 6 -9
Vs with a variable:
-25 6 -25 -20
-25 6 -25 -20
-25 6 -25 -20
-25 6 -25 -20
-25 6 -25 -20
Next we specify the x and the y:
>>> for _ in range(x)]for _ in range(y) ]
Next we just print it and create a new line every time a row is made
hope this helped :D
In the program While loop is used. In the while loop it divides the userNum by 2 in each iteration and prints the value of userNum. The inputs and corresponding outputs are written in the explanation.
<u>Explanation</u>:
In the while loop it divides the userNum by 2 in each iteration and prints the value of userNum.
import java.util.Scanner;
public class NonNegativeLooper
public static void main (String [] args)
Scanner scnr = new Scanner(System.in);
//initialize the userNum with 9
int userNum = 9;
//Repeat the loop until the userNum is not negative
while (userNum>=0)
System.out.println(Body);
//Prompt the user to enter the usrNum again
userNum = scnr.nextInt();
System.out.println(Done.);
return;
There’s literally no question here
def main():
print("This is meant for me to learn about different types of people.")
<em>#print("What is your favorite animal")</em>
favAnimal = input("What is your favorite animal?")
<em>#print("Wow that's a really cool animal.")
</em>
<em> #print("Do you know how to speak different languages")</em>
answer = input("Do you know how to speak different languages")
if(answer == "yes"):
print("That's amazing")
else:
print("You don't know how to speak different languages don't sweat it neither do I.")
main()
1. We have to comment/remove all those lines with the print () method that contain questions and "must" accept user input, because in the variable declaration the questions with the input are already printed.
2. Since there are no curly braces in Python, you should use tabs instead.
BASIC
(Beginners' All-purpose Symbolic Instruction Code)