CS 101 SoloLearn Python Basic Concepts

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Quotient Calculate and outputthe number of miles in 1000 kilometers.HintOne mile is 1.6 kilometers, so find thequotientof 1000 and 1.6. Use the floor division operator //.

#your code goes here x=1000 y=1.6 print(x//y) output=264

Which of the following operators is used to calculate the remainder of division? // % / **

%

What is the result of this code? print( 7%(5 // 2) )

1. 7%(2)=1 5 // 2 is integer/floor division, basically how many 2s go into 5. It goes in twice, so 5 // 2 = 2. Notice the answer must be an integer. 7 % 2 is simply the remainder when 7 is divided by 2. 2 goes in 3 times with remainder 1, so the answer is 1.

What is the result of the following operation? print(1 + 4*3)

13

What is the output of the following code : print 9//2 (A) 4.5(B) 4.0(C) 4(D) Error

Answer: (C)Explanation: The '//' operator in Python returns the integer part of the floating number.

floats

Floats are used in Python to represent numbers that aren't integers(whole numbers).Some examples of numbers that are represented as floats are 0.5 and -7.8237591.They can be created directly by entering a number with a decimal point, or by using operations such as division on integers. print( 3/4 ) print( 0.42 )

quotient

Floor division is done using two forward slashes and is used to determine thequotientof a division (the quantity produced by the division of two numbers).

Exponentiation is the raising of one number to the power of another.This operation is performed using two asterisks **.

For example, if we want to calculate how much money we will have on the 5th day, we can use this expression: 0.01*(2**5) = 0.32 dollars (multiply the penny by 2 raised to the power of 5).

Remainder

Themodulo operatoris carried out with a percent symbol (%) and is used to get theremainderof a division.

print( 8 / 2 ) print( 6 * 7.0 ) print( 4 + 1.65 )

dividing any two integers produces a float.A float is also produced by running an operation on two floats, or on a float and an integer.

The modulo operator is carried out with a percent symbol (%) and is used to get the remainder of a division. print(20 % 6) print(1.25 % 0.5)

for number in range(1, 10): if(number % 2 != 0): print(number)

You are offered a choice of either $1.000.000 or $0.01 (one penny) doubled every day for 30 days (the resulting amount is doubled every day). Task:Write a program to calculate the amount that will result from the doubling to understand which choice results in a larger amount.

print(0.01*(2**30))

produce code that output 10 raised to the 5th power.

print(10**5)

Fill in the blank to output the quotient of dividing 100 by 42.

print(100//42)


Kaugnay na mga set ng pag-aaral

Chapter 33: Introduction to the Immune System

View Set

ECON 202 FINAL Savings Interest Rates Loanable funds

View Set