Test 3

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

Python includes everything until the closing parentheses, even if it is not on the same line.

# OUTPUT # Display the results for the user, repeating the input values. print("For your weight of " + strWeight + " pounds and height of " + strHeight + " inches, your BMI is " + str(BMI) + " which is " + category + ".")

You wrote a program to find the factorial of a number. In mathematics, the factorial operation is used for positive integers and zero. What does the function return if the user enters a negative three? def factorial(number): product = 1 while number > 0: product = product * number number = number - 1 return product strNum = input("Enter a positive integer: ") num = int(strNum) print(factorial(num))

1

Create an Outline of the Plan

1. Define the problem precisely. Create a username from the first three letters of first name and first four letters of the last name. 2. Gather data. Ask the user for their first name (firstName) and last name (lastName). 3. Perform any needed calculations or data manipulations. Does the user have at least three characters in the first name and four characters in the last name? 4. If yes, create the username with slices. If not, add numbers as needed. 5. Communicate the results, along with an interpretation as needed. Display the username as output. 6. Check the accuracy of your calculations and data manipulations. Test the program with users having long names and short names.

What Grade Do I Need? In a math class, the students take five tests. The average of those five tests is the course grade. The course grade needs to be at least 90 in order to earn an A for the course. Plan a program that will ask students for their first four grades and then calculate the grade needed on the fifth test in order for the average to be at least 90.

1. Define the problem precisely. Find the grade needed on the fifth test in order for the average of five scores to be at least 90. 2. Gather data. Ask the student for the grades on the first four tests. 3. Perform any needed calculations or data manipulations. Calculate the needed grade on the fifth test. 4. Communicate the results, along with an interpretation as needed. Display the needed grade for the user. 5. Check the accuracy of your calculations and data manipulations. Test several sets of grades. To check accuracy, take the user's first four grades together with the predicted grade on the fifth test to see if the average is 90.

Design Steps Input-Process-Output model

1. Define the problem precisely. 2. Gather data. (Input) 3. Perform any needed calculations or data manipulations. (Process) 4. Communicate the results, along with an interpretation as needed. (Output) 5. Check the accuracy of your calculations and data manipulations.

Use the factorial operation to evaluate 4!.

24

What is the next number in the Fibonacci sequence? 1, 1, 2, 3, 5, 8, 13, 21, _____

34

What is the output of the following program? >>> phrase = "help me" >>> len(phrase) ' _____ '

7

What is the output for the following code? Enter the result in the blank.

>>> num = "abcdefghi" >>> num[2:5] ' ______ ' cde

screen magnifiers

A common tool used by the visually impaired. These technologies include physical magnifiers or software features that allow users to see a part of the screen in relation to other parts of the screen. software acts as a magnifying glass that you can move around the screen not just zooming in and out

Suppose your user entered a weight of 115.6. What will be the result of the following code? strWeight = input("Enter your weight in pounds: ") weight = int(strWeight) print (weight)

An error occurs.

Which of the following statements are true regarding accessibility? Select 3 options.

Assistive technologies can provide accessibility to those with disabilities or impairments. Accessibility also applies to mobile users and those with lower speed connections. Accessibility can be provided using hardware devices, applications, software features, and conscious design decisions.

PLAN BEFORE YOU CODE

BMI weight in pounds/ (height in inches)^2 BMI Weight Category Below 18.5 Underweight 18.5 to 24.9 Normal 25 to 29.9 Overweight 30 to 39.9 Obese 40 and above Morbidly Obese ​# A program to find BMI # INPUT # Get the user's weight in pounds. # Get the user's height in inches. # PROCESS # Calculate the BMI. # Determine the weight category. # OUTPUT # Display the results for the user, repeating the input values.

Which step comes last?

Check for accuracy.

Which step comes first?

Define the problem.

Choose the steps in the order discussed in the lesson. Step 1: Step 2: Step 3: Step 4: Step 5:

Define the task Input Process Output Check Accuracy

Write a recursive function fib to find the nth Fibonacci number.

For instance, fib(6) would be eight.

head pointers

If you cannot use your hands devices that the user wears on their head to push keys.

You designed a program to create a username using the first three letters from the first name and the first four letters of the last name. You are testing the program, the last step in the process. For a user named John Smith, what username should the program create?

JohSmit

Which features are important when you plan a program? Select 4 options.

Knowing what you want the program to do. Knowing how to find the result needed. Knowing what the user needs the program to accomplish. Knowing what information is needed to find the result.

tracking devices

Motion or eye another way for those with mobility impairment to interact with the computer. These tracking devices interpret where the user wants to move the mouse.

What is the value of the variable result after this code is executed? >>> a = 7 >>> b = 2 >>> c = 0 >>> result = a * b - b / (c + b) >>> result

Output: 13.0

You designed a program to create a username using the first three letters from the first name and the first four letters of the last name. You are testing your username program again for a user whose name is Paula Mano. The output should be _____.

PauMano

RECURSIVE FACTORIAL

Recursion: is the process of defining something in terms of itself. In mathematics, recursion is used with a sequence of numbers. When you define a sequence using recursion, each number is defined in terms of the previous number. 3, 8, 13, 18, 23, 28, and so on. recursive definition The first number is three. For the rest of the list, add five to the previous number in the list to get the next number.

_________ allow(s) users to enter text and control the computer with their voice.

Speech input software

________ use(s) a synthesized voice to read text on the screen.

Text-to-speech

ASCII code

The numerical equivalent of a character

What is the value of the variable moneyDue after these lines of code are executed? >>> numSodas = 2 >>> costSodas = 1.50 >>> moneyDue = numSodas * costSodas

The value of moneyDue is 3.0.

Fibonacci numbers is usually defined recursively.

This version is slightly modified because it starts with two ones. The list starts out usually with two ones. 1,1 After that, each new number is the sum of the previous two numbers. The sum of one and one is two. 1, 1, 2 The next number is 1 + 2, which is 3. 1, 1, 2, 3 The next number is 2 + 3, which is 5. 1, 1, 2, 3, 5 This keeps going forever. 1, 1, 2, 3, 5, 8, 13, 21, and so on.

Since Python executes the code indented after the first true condition, you do not need to add the lower boundary of 18.5.

To read the first "elif" line, the BMI had to be more than 18.5. ​# Determine the weight category. if BMI < 18.5: category = "underweight" elif BMI <= 24.9: category = "normal" elif BMI <= 39.9: category = "overweight" else: category = "morbidly obese"

____________ interpret(s) where a user wants to move the mouse through motions or eye movements.

Tracking devices

What is the output for the following code? >>> phrase = "help23" >>> phrase.isalnum()

True

What is the best way to create a pseudocode plan within your program?

Use comments in a file.

Accessibility Standards Accessibility is measured based on standards.

Web accessibility is evaluated using the Web Content Accessibility Guidelines (WCAG) created by the World Wide Web Consortium (WC3). The standards are based on those defined by the Web Accessibility Initiative (WAI), a task force formed by the W3C.

whitespace:

Whitespace characters do not have a visible presence (e.g., space, tab, and others)

Escape Character: result

\\ : Inserts a backslash (\) \' : Inserts a single quote (') \" : Inserts a double quote (") \n : Moves to a new line \tHorizontal tab

sequence

an ordered set of elements A string is a type of sequence

Which of the following shows the assignment of a string to a variable? Select 3 options.

answer = '23' answer = "23" answer = input("How old are you? ")

What is the missing line of code? >>> answer = "happy birthday" >>> _____ 'Happy birthday'

answer.capitalize()

A(n) _______ is a statement that assigns a value to a variable.

assignment statement

Often screen readers do not convey all of the necessary information to programmers about the programming environment or their code. One solution for communicating indentations and the distinction between code and text is the use of _____.

audio cues

Recursion occurs when a function _______.

calls itself

switch entry device

can also be added to an on-screen keyboard so that the user can click a switch when the cursor moves across the key they want to choose.

The formula to convert Fahrenheit (F) temperature to Celsius (C) is C=F−321.8 Which line of code will accomplish this conversion?

celsius = (fahrenheit - 32) / 1.8

Center(number of spaces, character)

centers the string within a spaces indicated and fills the unused spaces with the character. ​>>> spacedFriend = friend.center(20,'_') >>> spacedFriend '________Alex________'

Whitespace

characters do not have a visible presence, such as space, tab, and others. ASCII code for characters you cannot see

Arithmetic with String Data

concatenate strings (join them without spaces in between) with the plus sign (+) create multiples of a string by using string multiplication ​​>>> yourName = 'Shaquita' >>> manyYou = yourName * 3 >>> manyYou 'ShaquitaShaquitaShaquita'

.upper()

converts any lowercase characters to uppercase.

.lower()

converts any uppercase characters to lowercase.

FACTORIAL CALCULATION

factorial: A factorial of a positive integer is the product of that integer times each positive integer smaller than itself. The symbol used for factorial is an exclamation point. The expression 5! is read as "five factorial" and equals 120. 5! = 5*4*3*2*1=120

capitalize()

function capitalizes the first letter in a string ​>>> friend = "alex" >>> print(friend.capitalize()) Alex

What is the output for the following code? >>> answer = "Hello Dad" >>> answer.lower() ' ______ '

hello dad

Cognitive

impairment can include intellectual issues, mental illness, or learning disabilities. Cognitive abilities can decline as you age too.

Auditory

impairments affect users' ability to hear content devices like hearing aids, users can read transcripts and captions, provided by the developer, instead of listening to the content.

In your program to calculate the slope, supply the missing word. The program is incomplete. # Find the slope of the user's two points # Get the points xOne = _________ ("Enter the x-coordinate of the first point: ")

input

Identify the order of steps in the structure of a program. Other steps may be left out. Step 1: Step 2: Step 3:

input process output

You are writing a program to ask the user for the coordinates of two points and then find the slope. Identify each step as input, process, or output. Not all steps are listed. #Ask the user for the x-coordinate of the first point. _____ #Calculate the slope. _____ #Display the slope. _____

input process output

index Index 0 1 2 3 4 5 6 7 8 9 10 11 12 Character B o b i s a d o g .

integers beginning with zero for the first character Every character in a string is assigned an index Even the spaces are assigned an index

Text-to-speech

is a feature embedded in many programs that uses a synthesized voice to read text on the screen. examples: JAWS for Windows and Voiceover for Mac.

screen reader

is an application that assists visually impaired users by providing the text and image contents of a screen, via audio or braille.

A command line interface (CLI)

is another good option for a visually impaired programmer, since it tends to be more accessible than a graphical programming environment.

Adhering to high accessibility standards,

is not only the right thing to do, it is the law in some locations.

Accessibility

is the degree to which a product or service is readily available and usable for as many people as possible.

Be sure you add enough of an explanation so your user knows what that information represents.

not: 23.5 normal

omplete the function to return the factorial of the parameter using recursion. def recursiveFactorial(number): if number > 1: return number * recursiveFactorial(________) else: return 1 stringNum = input("Enter a positive integer: ") num = int(stringNum) print(recursiveFactorial(num))

number - 1

Alternative text

provides a description of images that can be read by screen readers. substitute content when the images won't display because of connection issues developer of the content is responsible for supplying the alternative text that describes the image.

You created a plan for the program to find the slope, as shown below. # Find the slope of the user's two points # Get the points # Calculate the slope # Display the result This plan is in the form of _____.

pseudocode

One of them, ________, occurs when something is defined in terms of itself.

recursion

In programming,

recursion occurs when a function calls itself.

.strip()

removes the spaces from the beginning and end of a string.

Complete the function to return the factorial of the parameter. def factorial(number): product = 1 while number > 0: product = product * number number = number - 1 _______ product strNum = input("Enter a positive integer: ") num = int(strNum) print(factorial(num))

return

.islower()

returns True if all letters in the string are lowercase and there is at least one letter. It ignores numbers as long as there is at least one letter.

.isalpha()

returns True if all the characters are letters and the string has at least one character.

.isalnum()

returns True if all the characters are letters or digits and the string has at least one character.

.isdigit()

returns True if the string contains only digits and has at least one character; it returns False if there is a decimal point.

.isspace()

returns True if the string is composed entirely of whitespace characters.

ord()

returns the ASCII code for the single character in the parentheses. >>> ord('D') 68 enter ' ' inside letter

chr()

returns the character when given the numerical equivalent in the parentheses. term-16 >>> chr(68) 'D'

len(string)

returns the length of a string Python counts punctuation and whitespace characters

len(string)

returns the length of the string.

A person with a visual impairment could use a _________ to help them interact with a computer.S'\ omeone with a mobility impairment might use ___________ to interact with web sites and applications. _________ are an assistive tool that helps someone with a hearing impairment, access audio content.

screen reader tracking device Transcripts

slicing

selecting a piece of a string ​​>>> sentence[2:7] 'b is ' starts with the character with an index of 2 and stops with the character BEFORE character 7. ​​>>> sentence = "Bob is a dog." ​​>>> sentence[7:12] 'a dog'

What is the missing line of code? >>> sentence = "Programming is fun!" >>> _____ 'gra'

sentence[3:6]

Assistive technologies,

specialized tools that help provide access to disabled individuals

Check the Accuracy of Your Calculations

test data that will give you a result in each weight category and at each boundary. You can search online for a BMI calculator to make testing go faster.

If the user is likely to enter decimal values,

use float() to prevent errors caused by trying to convert a decimal to an int.

A(n) _________ is an identifier used to store a value.

variable

turn string version of the user's input into a float will prevent errors

weight = str(110.5) ​# A program to find BMI # INPUT # Get the user's weight in pounds. strWeight = input("What is your weight in pounds? ") weight = float(strWeight)

Unicode

which allows numerical values for over a million characters, but currently only about 10 percent of those numbers have an assigned character. (The original ASCII code only used seven bits, only allowing for codes from 0 to 127.)

speech input software

which allows users to enter text and control the computer with their voice. (voice recognition technology)

Escape Characters

you can use \' and \" in a string when you want the string itself to include quotation marks. ​​>>> print("Mom said \"hi\".") Mom said "hi". ​​>>> print("Mom said \"hi\". \n Dad said \'Call soon.\'") Mom said "hi". Dad said 'Call soon.'

An alternative output is to use two print() statements, one to repeat the user's input and one to share the result.

​# Display the results for the user, repeating the input values. print("Your weight is " + strWeight + " pounds your height is " + strHeight + " inches.") print("Your BMI is " + str(BMI) + " which is " + category + ".")

BMI program

​# INPUT # Get the user's weight in pounds. strWeight = input("What is your weight in pounds? ") weight = float(strWeight) # Get the user's height in inches. strHeight = input ("What is your height in inches? (1 ft = 12 in) ") height = float(strHeight) # PROCESS # Calculate the BMI. BMI = 703 * weight / height ** 2 BMI = round(BMI, 1) # Determine the weight category. if BMI < 18.5: category = "underweight" elif BMI <= 24.9: category = "normal" elif BMI <= 39.9: category = "overweight" else: category = "morbidly obese" # OUTPUT (alternative version) # Display the results for the user, repeating the input values. print("Your weight is " + strWeight + " pounds your height is " + strHeight + " inches.") print("Your BMI is " + str(BMI) + " which is " + category + ".")

dividing by a large number, rounding to one decimal place will improve the quality of your output.

​# PROCESS # Calculate the BMI. BMI = 703 * weight / height ** 2 BMI = round(BMI, 1) python uses pemdas, so no parentheses are needed in the calculation of BMI. (optional)

permanently change friend to have the first letter capitalized

​>>> friend = friend.capitalize() ​>>> friend 'Alex'

A Python Program to Calculate Factorials Add some error handling to your program to stop the user who enters a decimal number, zero, or a negative number. when entering a negative or zero output is 1

​def factorial(number): product = 1 while number > 0: product = product * number number = number - 1 return product strNum = input("Enter a positive integer: ") num = int(strNum) print(factorial(num))

recursively find the factorial of a number

​def recursiveFactorial(number): if number > 1: return number * recursiveFactorial(number - 1) else: return 1 stringNum = input("Enter a positive integer: ") num = int(stringNum) print(recursiveFactorial(num)) Test the program with other values.

You can select a particular character in a string by using its index. If you try to access a character whose index is not valid, you will get an error statement. negative numbers count backward from the end of the string. >>> sentence[-2] 'g'

​​>>> sentence = "Bob is a dog." >>> sentence[2] 'b' >>> sentence[11] 'g'


Ensembles d'études connexes

Quiz chapter 10_psychology 101_True&False

View Set

Grammar Unit 7 & 8 (Possessive Cases and Forms)

View Set