Sololearn Python Core Lesson 1 to 7 Basic Concepts

Ace your homework & exams now with Quizwiz!

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.

Floor Division

Floor division is done using two forward slashes and is used to determine the quotient of a division

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

%

print('Hello world!')

Hello world!

print( 3/4 ) print( 0.42 )

0.75 0.42

Exponentiation is the raising of one number to the power of another.This operation is performed using two asterisks **. Let's use exponentiation to solve a known problem.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. Hint:Let's see how exponentiation can be useful to perform the calculation.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).

# your code goes here H = 0.01 num = 1 while num < 31: a = H*(2**num) num += 1 print (a) Input No Input Your Output Answer 10737418.24 Expected Output 10737418.24

Your First Program Write a program to print "Python is fun". Note that the sentence starts with a capital letter. Hint Use the print() function.

#output "Python is fun" print("Python is fun")

Drag & drop the correct option to output "Hi". __________("Hi")

print("Hi")

quotient

(the quantity produced by the division of two numbers)

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

1

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

13

print( 2 * (3 + 4) ) print( 10 / 2 )

14 5 . 0 _________________________________ why it equal 14? 2 * 3 = 6 & 2 * 4 = 8 +6 = 14

print(1 + 2 + 3 + 4.0 + 5)

15 . 0

What is the output of this code? print( 10//4 ) 3 2 0

2

print(20 % 6) print(1.25 % 0.5)

2 0.25

What is the output of this code? print( 8 ** (1/3) ) 2 3.0 2.0

2.0

print( 20 // 6 )

3

You can also use floats in exponentiation. For example, the following code will result in the square root of 9: print(9 ** (1 / 2) )

3 . 0

print(2**5)

32

Guess the output of this code: print( (3**2)//2 )

4

Enter a calculation directly into the print statement: print(2 + 2) print(5 + 4 - 3)

4 6

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

4.0 42.0 5.65

What does this code output? print(1 + 2 + 3)

6

Which option is output by this code? print((4 + 8) / 2) choice 6 8 6.0

6 . 0

Which of these will not be stored as a float? 7.0 2/4 7

7 it's not a float it's a integers

Note>>

A float can be added to an integer, because Python silently converts the integer to a float.

Float

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

Python

A high-level programming language, with applications in numerous areas, including web programming, scripting, scientific computing, and artificial intelligence!

Modulo Operator

Carried out with a percent symbol (%) and is used to get the remainder of a division.

NOTE>>

Computers can't store floats perfectly accurately, in the same way that we can't write down the complete decimal expansion of 1/3 (0.3333333333333333...). Keep this in mind, because it often leads to infuriating bugs!

Fill in the blank to output 5 raised to the 3rd power. print(5____3)

Fill in the blank to output 5 raised to the 3rd power. print(5**3)

print('Hello world!') print('Hello world!') print('Spam and eggs...')

Hello world! Hello world! Spam and eggs...

Simple Operation

Lesson 2.1

Float

Lesson 3.1

Exponentiation

Lesson 4.1

Quotient & remainder

Lesson 5.1

Module 1 Quiz

Lesson 6.1

Python is a: Set of editing tools Development environment Programming language

Programming language

asterisk *

To indicate multiplication and a forward slash / to indicate division.

exponentiation

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

NOTE>>

You can chain exponentiations together. In other words, you can rise a number to multiple powers. For example, 2**3**2.

parentheses

parentheses to determine which operations are performed first.

Fill in the required parentheses to create a valid print statement. print ___"I love Python"___

print ("I love Python")

Rearrange the code to generate the following output: A B C print("B") print("A") print("C")

print("A") print("B") print("C")

Fill in the blanks to output "I love Python". _________("I love Python"__

print("I love Python")

Drag & drop from the options below to 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)

print(100//42)


Related study sets

Chapter 40: A World without Borders (QUESTIONS)

View Set

Cap 17: Entropía, energía libre y equilibrio

View Set

Managment & Leadership NCLEX Questions

View Set

course point assignment 2 Adult health

View Set

OB Exam 1 Practice Ch's 1 2 3 4 5 6

View Set

Writing Equations of Lines All Form

View Set