Questions from text Chapter 5

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

In Python a module is: (A) A file containing Python definitions and statements intended for use in other Python programs. (B) A separate block of code within a program. (C) One line of code in a program. (D) A file that contains documentation about functions in Python.

(A) A file containing Python definitions and statements intended for use in other Python programs.

True / False: All standard Python modules will work in activecode. (A) True (B) False

(B) False * Only turtle, math, and random have been ported to work in activecode at this time

math module

- math.pow(x, y)= x raised to power y - math.sqrt(x)= square root of x - math.pi= pi

"in" versus "in range"

= "in" = can only have one variable, does exactly as that variable says = "in range" = can have 3 or more variables.(1,10,3) means execute the code 1, 4, 7

Randint function

If we wanted a random integer, we can use the randint function Randint accepts two parameters: a lowest and a highest number. Generate integers between 1,5. The first value should be less than the second.

The Pythagorean Theorem tells us that the length of the hypotenuse of a right triangle is related to the lengths of the other two sides. Look through the math module and see if you can find a function that will compute this relationship for you.

import math side1 = 3 side2 = 4 hypotenuse = math.hypot(side1,side2) print(hypotenuse)

Repeat the above exercise but this time print 10 random numbers between 25 and 35.

import random how_many= 10 for count in range(how_many): alex= random.randint(25,35) (or 24,36) print(alex)

Use a for statement to print 10 random numbers.

import random howmany = 10 for counter in range(howmany): arandom = random.random() print(arandom)


Ensembles d'études connexes

Biology 2 Test 1 Sample Questions

View Set

ELA 2b: Quiz 4.13 - A Dish Best Served Cold

View Set

Marriage and Family Chapters 5, 6, 7 quiz

View Set

Chapter 7: Introduction to Fallacies

View Set

Fundamentals Of Real Estate - Unit 2 (17% - 25Q)

View Set

Cardio Practice questions, Neuro NCLEX, NCLEX Neuro disorders, Lewis Chapter 48, Endocrine, Liver Failure, Hepatitis, cholecystitis, pancreatitis, NCLEX, Urinary NCLEX Questions, Med-surg Test #3, Urinary NCLEX QUESTIONS, Fluids and Electrolytes_Test...

View Set