Crash Course on Python

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

How does Python compare to other programming languages?

Each programming language has its advantages and disadvantages.

What are functions in Python?

Functions are pieces of code that perform a unit of work.

Python is an example of what type of programming language?

General purpose scripting language

What are the values passed into functions as input called?

Parameters

What are some characteristics of the Python programming language? Check all that apply.

Python programs are easy to write and understand. The Python interpreter reads our code and transforms it into computer instructions. We can practice Python using web interpreters or codepads as well as executing it locally.

What does the print function do in Python?

The print function outputs messages to the screen

What's automation?

The process of replacing a manual step with one that happens automatically.

What's the syntax of a language?

The rules of how to express things in that language

What is the purpose of the def keyword?

Used to define a new function

Replace the ___ placeholder and calculate the Golden ratio: \frac{1+\sqrt{5}}{2}21+5​​. Tip: to calculate the square root of a number xx, you can use x**(1/2).

ratio = ((1+(5**(1/2)))/2) print(ratio)

Fill in the blanks so that the code prints "Yellow is the color of sunshine".

color = "Yellow" thing = "sunshine" print(color + " is the color of " + thing)

This function converts miles to kilometers (km). Complete the function to return the result of the conversion Call the function to convert the trip distance from miles to kilometers Fill in the blank to print the result of the conversion Calculate the round-trip in kilometers by doubling the result, and fill in the blank to print the result

def convert_distance(miles): km = miles * 1.6 return km result = convert_distance(55) print("The distance in Kilometers is " + str(result)) print("The round-trip in Kilometers is " + str(result*2))

Let's revisit our lucky_number function. We want to change it, so that instead of printing the message, it returns the message. This way, the calling line can print the message, or do something else with it if needed. Fill in the blanks to complete the code to make it work.

def lucky_number(name): number = len(name) * 9 print("Hello " + name + ". Your lucky number is " + str(number)) (lucky_number("Kay")) (lucky_number("Cameron"))

Most hard drives are divided into sectors of 512 bytes each. Our disk has a size of 16 GB. Fill in the blank to calculate how many sectors the disk has. Note: Your result should be in the format of just a number, not a sentence.

disk_size = 16*1024*1024*1024 sector_size = 512 sector_amount = (((16*1024*1024*1024)/512)) print(sector_amount)

This function compares two numbers and returns them in increasing order. Fill in the blanks, so the print statement displays the result of the function call in order. Hint: if a function returns multiple values, don't forget to store these values in multiple variables

# This function compares two numbers and returns them # in increasing order. def order_numbers(number1, number2): if number2 > number1: return number1, number2 else: return number2, number1 # 1) Fill in the blanks so the print statement displays the result # of the function call smaller,bigger = order_numbers(100, 99) print(smaller,bigger)

What's a computer program?

A list of instructions that the computer has to follow to reach a goal

What is a computer program?

A step-by-step recipe of what needs to be done to complete a task, that gets executed by the computer.

In this scenario, two friends are eating dinner at a restaurant. The bill comes in the amount of 47.28 dollars. The friends decide to split the bill evenly between them, after adding 15% tip for the service. Calculate the tip, the total amount to pay, and each friend's share, then output a message saying "Each person needs to pay: " followed by the resulting number.

bill = 47.28 tip = 0.15 * bill total = bill + tip share = total/2 print("Each person needs to pay: " + str (share))

This code is supposed to take two numbers, divide one by another so that the result is equal to 1, and display the result on the screen. Unfortunately, there is an error in the code. Find the error and fix it, so that the output is correct.

numerator = 10 denominator = 10 result = numerator / denominator print(result)

Write a Python script that outputs "Automating with Python is fun!" to the screen.

print ("Automating with Python is fun!")

Convert this Bash command into Python:

print ("Have a nice day")

Output a message that says "Programming in Python is fun!" to the screen.

print ("Programming in Python is fun!")

Fill in the correct Python command to put "My first Python program" onto the screen.

print("My first Python program")

What do you call a combination of numbers, symbols, or other values that produce a result when evaluated?

An expression

Which of the following tasks are good candidates for automation? Check all that apply.

Creating a report of how much each sales person has sold in the last month. Setting the home directory and access permissions for new employees joining your company. Populating your company's e-commerce site with the latest products in the catalog.

Which of these scenarios are good candidates for automation? Select all that apply.

Generating a sales report, split by region and product type Copying a file to all computers in a company Sending personalized emails to subscribers of your website

What are keywords in Python?

Keywords are reserved words that are used to construct instructions.

What are semantics when applied to programming code and pseudocode?

The effect the programming instructions have

What's the difference between a program and a script?

There's not much difference, but scripts are usually simpler and shorter.

This code is supposed to display "2 + 2 = 4" on the screen, but there is an error. Find the error in the code and fix it, so that the output is correct.

a = 2 b = a+a print("2 + 2 = " + str(b) )

Select the Python code snippet that corresponds to the following Javascript snippet: for (let i = 0; i < 10; i++) { console.log(i); }

for i in range(10): print(i)

Fill in the correct Python commands to put "This is fun!" onto the screen 5 times.

for i in range(5): print("This is fun!")

Use Python to calculate how many different passwords can be formed with 6 lower case English letters. For a 1 letter password, there would be 26 possibilities. For a 2 letter password, each letter is independent of the other, so there would be 26 times 26 possibilities. Using this information, print the amount of possible passwords that can be formed with 6 letters.

print(26 * 26 * 26 * 26 * 26 * 26)

Keeping in mind there are 86400 seconds per day, write a program that calculates how many seconds there are in a week, if a week is 7 days. Print the result on the screen. Note: Your result should be in the format of just a number, not a sentence.

print(86400*7)

Combine the variables to display the sentence "How do you like Python so far?"

print(str(word1) + " " + str(word2) + " " + str(word3) + " " + str(word4) + " " + str(word5) + " " + str(word6) + " " + str(word7))


Set pelajaran terkait

2: Sensations and Perception [EAR]

View Set

SGQ 13, SGQ 14, SGQ 15, SGQ 16, SGQ 18, SGQ 19

View Set

Professional Cooking - Chapter 15 "Understanding Meats and Game"

View Set

Google Search Optimization Course

View Set

Unidad 6 Las costumbres, los valores y los comportamientos

View Set

EMTB CH 15 HW and Quiz Questions

View Set

Final exam- Alabama life and health

View Set