Section 1
.pdf
keyboard_arrow_up
School
Southern New Hampshire University *
*We aren’t endorsed by this school
Course
140 - X625
Subject
Computer Science
Date
Apr 3, 2024
Type
Pages
6
Uploaded by DeaconCaterpillar4154
Students:
Section 1.3 is a part of 1 assignment:
1-3 zyBooks Participation Activities
Includes:
PA
1.3 Basic input and output
Basic text output
Printing of output to a screen is a common programming task. This section describes basic output; later sections have
more details.
The primary way to print output is to use the built-in function print()
. Printing text is performed via:
print('hello world')
. Text enclosed in quotes is known as a string literal
. Text in string literals may have letters,
numbers, spaces, or symbols like @ or #.
Each print statement will output on a new line. A new output line starts after each print statement, called a newline
. A
print statement's default behavior is to automatically end with a newline. However, using print('Hello', end=' ')
,
specifying end=' '
, keeps the next print's output on the same line separated by a single space. Any space, tab, or newline is
called whitespace
.
A string literal can be surrounded by matching single or double quotes: 'Python rocks!'
or "Python rocks!"
.
Good practice is to use single quotes for shorter strings and double quotes for more complicated text or text that contains
single quotes (such as
print("Don't eat that!")
).
Figure 1.3.1: Printing text and new lines.
# Each print statement starts on a new line
print
(
'Hello there.'
)
print
(
'My name is...'
)
print
(
'Carl?'
)
Hello there.
My name is...
Carl?
# Including end=' ' keeps output on same line
print
(
'Hello there.'
, end
=
' '
)
print
(
'My name is...'
, end
=
' '
)
print
(
'Carl?'
)
Hello there. My name is... Carl?
PARTICIPATION
ACTIVITY
1.3.1: Basic text output.
1)
Select the statement that prints the
following: Welcome!
print(Welcome!)
print('Welcome!")
print('Welcome!')
2)
Which pair of statements print output
on the same line?
print('Halt!')
print('No access!')
print('Halt!', end=' ')
print('No access!')
print(Halt!, end=' ')
print(No Access!, end=' ')
PARTICIPATION
ACTIVITY
1.3.2: Basic text output.
1)
Type a statement that prints the
following: Hello
CHALLENGE
ACTIVITY
1.3.1: Output simple text.
Write the simplest statement that prints the following:
3 2 1 Go!
Note: Whitespace (blank spaces / blank lines) matters; make sure your whitespace exactly
matches the expected output.
Learn how our autograder works
553398.3976864.qx3zqy7
Feedback?
Feedback?
Check
Show answer
Feedback?
''' Your solution goes here '''
1
2
3
CHALLENGE
ACTIVITY
1.3.2: Output an eight with asterisks.
Output the following ±gure with asterisks. Do not add spaces after the last character in each
line.
*****
* *
*****
* *
*****
Note: Whitespace (blank spaces / blank lines) matters; make sure your whitespace exactly
matches the expected output.
Learn how our autograder works
553398.3976864.qx3zqy7
Outputting a variable's value
The value of a variable can be printed out via: print(variable_name)
(without quotes).
Figure 1.3.2: Printing the value of a variable.
wage = 20
print
(
'Wage is'
, end
=
' '
)
print
(
wage
) # print variable's value
print
(
'Goodbye.'
)
Wage is 20
Goodbye.
PARTICIPATION
ACTIVITY
1.3.3: Basic variable output.
1)
Given the variable num_cars = 9, which
statement prints 9?
print(num_cars)
print("num_cars")
PARTICIPATION
ACTIVITY
1.3.4: Basic variable output.
1)
Write a statement that prints the
value of the variable num_people.
Outputting multiple items with one statement
Programmers commonly try to use a single print statement for each line of output by combining the printing of text,
variable values, and new lines. The programmer simply separates the items with commas; each item in the output will be
separated by a space. Such combining can improve program readability, because the program's code corresponds more
closely to the program's printed output.
Run
View your last submission
Feedback?
''' Your solution goes here '''
Run
View your last submission
Feedback?
Feedback?
Feedback?
Check
Show answer
Feedback?
1
2
3
Figure 1.3.3: Printing multiple items using a single print statement.
wage = 20
print
(
'Wage:'
, wage
) # Comma separates multiple items
print
(
'Goodbye.'
)
Wage: 20
Goodbye.
A common error is to forget the comma between items, as in print('Name' user_name)
.
Newline characters
Output can be moved to the next line by printing \n
, known as a newline character
. Ex: print ('1\n2\n3') prints "1" on the
±rst line, "2" on the second line, and "3" on the third line of output. \n
consists of two characters, \ and n, but together are
considered by the Python interpreter as a single character.
Figure 1.3.4: Printing using newline characters.
print
(
'1\n2\n3'
)
1
2
3
Using print() by itself without any text also prints a single newline.
Figure 1.3.5: printing without text.
print
(
'123'
)
print
()
print
(
'abc'
)
123
abc
NOTE: In a normal programming environment, program input is provided interactively and completed by pressing the
enter key. The enter key press would insert a newline. Since zyBooks input is pre-entered, no enter key press can be
inferred. Thus, activities that require pre-entered input may need extra newline characters or blank print statements in
zyBooks, compared to other environments.
PARTICIPATION
ACTIVITY
1.3.5: Output simulator.
The tool below allows for experimenting with print statements. The variables
country_population = 1344130000
and country_name = 'China'
have been
de±ned and can be used in the simulator.
Try printing the following output:
The population of China was 1344130000 in 2011.
PARTICIPATION
ACTIVITY
1.3.6: Single print statement.
Assume variable age = 22, pet = "dog", and pet_name = "Gerald".
1)
What is the output of
print('You are', age, 'years old.')
2)
What is the output of
print(pet_name, 'the', pet, 'is', age)
CHALLENGE
ACTIVITY
1.3.3: Enter the output.
Type the program's output.
Note:
Each print()
outputs a new line, so create a newline after your output by pressing
Enter
or Return
on your keyboard.
Feedback?
Feedback?
Feedback?
print(
'Change this string!'
)
Change this string!
Feedback?
Check
Show answer
Check
Show answer
Feedback?
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Questions
INFS3410
Practice Questions
Chapters 1, 2 and 3
The Following is an example run of an educational program for
school children. The program help kids to practice their
additions and subtraction skills.
Your task is to develop a program that can achieve the same
exact thing. Bear in mind the following important guidelines:
- The user may choose between additions and subtractions
- The user may choose the difficulty level (easy, medium,
hard)
- The program should display 5 questions and calculate the
total score
- No two questions should be the same
Please enter your name: Hafedh AlShihi
**************
Hello Hafedh AlShihi
Welcome to our Additions / Subtractions
Practice
****k*********
Which operation you want to practice? Type
1 for Additions, or Type 2 for
subtractions: 2
Please select your difficulty level
Type 1 for Easy (numbers 1 to 10)
Type 2 for Medium (numbers 10 to 100)
Type 3 for Hard (numbers 100 to 1000)
1
Here are 5 easy-level subtraction
questions, please attempt all:
How…
arrow_forward
C++ Visual 2019
A particular talent competition has five judges, each of whom awards a score between 0 and 10 to each performer. Fractional scores, such as 8.3, are allowed. A performer's final score is determined by dropping the highest and lowest score received, then averaging the three remaining scores. Write a program that uses this method to calculate a contestant's score. It should include the following functions:
void getJudgeData() should ask the user for a judge's score, store it in a reference parameter variable, and validate it. This function should be called by main once for each of the five judges.
void calcScore() should calculate and display the average of the three scores that remain after dropping the highest and lowest scores the performer received. This function should be called just once by main and should be passed the five scores.
The last two functions, described below, should be called by calcScore, which uses the returned information to determine which of the…
arrow_forward
Java - Painting a Wall
arrow_forward
Problem:
A small company needs an interactive program to compute an employee’s paycheck. The payroll clerk will initially input the data, and given the input data, an employee's wage for the week should be displayed on the screen for the payroll check.
The data for the employee includes the employee's hourly pay rate and the number of hours worked that week. Wage is equal to the employee's pay rate times the number of hours worked (up to 40 hours). If the employee worked more than 40 hours, wage is equal to the employee's pay rate times 40 hours plus 1½ times the employee's pay rate times the number of hours worked above 40.
Instructions:
Match the action at the left-side with the correct step number at the right-side (the attached picture). Note that it may be possible to group more than one related actions in the same logical step / process without altering the essence of the algorithm.
In the program flow, input and checking of hourly pay rate should come before that of the number…
arrow_forward
5. A prime number is a number that is only evenly divisible by itself and 1. For example, the
number 5 is prime because it can only be evenly divided by 1 and 5. The number 6, how-
ever, is not prime because it can be divided evenly by 1, 2, 3, and 6.
Write a Boolean function named is_prime which takes an integer as an argument and
returns true if the argument is a prime number, or false otherwise. Use the function in a
program that prompts the user to enter a number then displays a message indicating
whether the number is prime.
6. In another program, use the function you wrote in question 5 to print the prime numbers
between 1 and 100 using for loop.
arrow_forward
Predefined Function: ceil(), floor(), rand(), srand0
1. Create a program that will round off a given number.
Example Program Output:
Enter a number to be round of: 10.5
Round off value: 10
Enter a number to be round of: 10.6
Round off value: 11
Enter a number to be round of: 10.4
Round off value: 10
Enter a number to be round of: 11.5
Round off value: 12
arrow_forward
Microwaves / Radio Waves
If a scientist knows the wavelength of an electromagnetic wave she can determine what type of
radiation it is. Write a program that asks for the wavelength in meters of an electromagnetic
wave and then displays what that wave is according to the following chart. (For example, a
wave with a wavelength of 1E-10 meters would be an X-ray.)
1x 10-11
1 x 10-8
4 x 10-7
7x 10-7
1x 10-3
1 x 10-2
Gamma Rays.
X Rays
Ultraviolet
Visible Light
Infrared
arrow_forward
JAVA:
arrow_forward
python language : complete the formula
COde with comments and output screenshot is must. No plagarism please
arrow_forward
LISP Function help please
A function that generates a random day of the week, then displays a message saying that "Today is ... and tomorrow will be ...".
Then use the built-in function random first to generate a number between 0 and 6 (including). The expression (random) by itself generates a random integer. You can call it with one parameter to return a value within the range from 0 to the value of the parameter-1. For example, (random 10) will return a value between 0 and 9.
Next, use the number generated at the previous step to retrieve the symbol for the day of the week from the list. Use the built-in elt.
Extract the symbol-name of the day first, then apply the built-in function capitalize to it. Use the result in the princ function call, and do the same thing for the next day.
Make the function return true (t) instead of the last thing it evaluates, to avoid seeing the message printed more than once.
arrow_forward
1. A prime number is a number that is only evenly divisible by itself and 1. For example, the number 5 is prime because it can only be evenly divided by 1 and 5. The number 6, however, is not prime because it can be divided evenly by 1, 2, 3, and 6.Write a Boolean function named is_prime which takes an integer as an argument and returns true if the argument is a prime number, or false otherwise. Use the function in a program that prompts the user to enter a number then displays a message indicating whether the number is prime.Tip:Recall that the % operator divides one number by another and returns the remainder of the division. In an expression such as num1 % num2, the % operator will return 0 if num1 is evenly divisible by num2.
arrow_forward
Use C Language
Airline Reservation System
A small airline has just purchased a computer for its new automated reservations system. The president has asked you to program the new system. You are to write a program to assign seats on each flight of the airline's only plane (capacity: 10 seats).
Your program should display the following menu of alternatives:
Please type 1 for "first class"
Please type 2 for "economy"
If the person types 1, then your program should assign a seat in the first class section (seats 1-5). If the person types 2, then your program should assign a seat in the economy section (seats 6-10). Your program should then print a boarding pass indicating the person's seat number and whether it is in the first class or economy section of the plane.
Use a single-subscripted array to represent the seating chart of the plane. Initialize all the elements of the array to 0 to indicate that all seats are empty. As each seat is assigned, set the corresponding elements of…
arrow_forward
JAVA Programming Problem 2 - Diving
In the sport of diving, seven judges award a score between 0 and 10, where each score may be a floating-point value. The highest and lowest scores are thrown out and the remaining scores are added together. The sum is then multiplied by the degree of difficulty for that dive. The degree of difficulty ranges from 1.2 to 3.8 points. The total is then multiplied by 0.6 to determine the diver’s score. Write a computer program that will ultimately determine the diver’s score. This program must include the following methods:
A method name inputValidScore that inputs one valid score for one judge for one diver. This method will return the valid score.
A method named inputAllScores that creates an array to store the scores for all judges for the diver. This method will fill the array with a valid score from each judge. This method does not take input arguments, but it does return the array of scores.
A method named inputValidDegreeOfDifficulty that inputs a…
arrow_forward
python
arrow_forward
Name Format - Use Java
arrow_forward
Lottery number in python
arrow_forward
LISP Function help please
LISP Programming only
A function that generates a random day of the week, then displays a message saying that "Today is ... and tomorrow will be ...".
Then use the built-in function random first to generate a number between 0 and 6 (including). The expression (random) by itself generates a random integer. You can call it with one parameter to return a value within the range from 0 to the value of the parameter-1. For example, (random 10) will return a value between 0 and 9.
Next, use the number generated at the previous step to retrieve the symbol for the day of the week from the list. Use the built-in elt.
Extract the symbol-name of the day first, then apply the built-in function capitalize to it. Use the result in the princ function call, and do the same thing for the next day.
Make the function return true (t) instead of the last thing it evaluates, to avoid seeing the message printed more than once.
arrow_forward
function is used to display anything on the screen in Python Programming Language.
arrow_forward
Tracking laps
Learning Objectives
In this lab, you will practice
writing functions, passing arguments and returning results from the function
printing the result of a function call
writing your code as a module
Instructions
Main Idea
An Olympic-size swimming pool is used in the Olympic Games, where the racecourse is 50 meters (164.0 ft) in length. "In swimming, a lap is the same as a length. By definition, a lap means a complete trip around a race track, in swimming, the pool is the race track. Therefore if you swim from one end to the other, you’ve completed the track and thus you’ve completed one lap or one length." (Source: What Is A Lap In Swimming? Lap Vs Length)
Write the function meters_to_laps() that takes a number of meters as an argument and returns the real number of laps. Complete the program to output the number of laps with two digits after the period.
Examples
Input:
150
Output :
3.00
Input:
80
Output:
1.60
Your program must define and call the following…
arrow_forward
HhhQuiz score: 80
Mid-term score: 68
Final score: 90.
arrow_forward
Computer Science
arrow_forward
python programming.
arrow_forward
PYTHON HOMEWORK QUESTION
def area(side1, side2): return side1 * side2
s1 = 12s2 = 6
Select all statements that correctly call the area function.
A. answer = area(s1,s2)B. print(f'The area is {area(s1,s2)}')C. area(s1,s2)D. result = area(side1,side2)
arrow_forward
1 # Calculator.py - This program performs arithmetic, ( +. -, *. / ) on two numb
2 # Input:
Interactive
Summary
3 # Output:
Result of arithmetic operation
4
In this lab, you complete a partially written Python program that includes a function that returns a
5 # Write performOperation function here
value. The program is a simple calculator that prompts the user for two numbers and an operator (
+, -, *, or / ).
7 if -_name_- == '-_main__':
numberOne = int(input("Enter the first number: "))
numberTwo = int(input("Enter the second number: "))
operation = input("Enter an operator (+ - * /): ")
8
The two numbers and the operator are passed to the function where the appropriate arithmetic
10
operation is performed. The result is then returned to where the arithmetic operation and result are
11
displayed.
12
# Call performOperation method here and store the value in "result"
13
For example, if the user enters 3, 4, and *, the following is displayed:
14
print(str(numberOne) + " " + operation +…
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Related Questions
- INFS3410 Practice Questions Chapters 1, 2 and 3 The Following is an example run of an educational program for school children. The program help kids to practice their additions and subtraction skills. Your task is to develop a program that can achieve the same exact thing. Bear in mind the following important guidelines: - The user may choose between additions and subtractions - The user may choose the difficulty level (easy, medium, hard) - The program should display 5 questions and calculate the total score - No two questions should be the same Please enter your name: Hafedh AlShihi ************** Hello Hafedh AlShihi Welcome to our Additions / Subtractions Practice ****k********* Which operation you want to practice? Type 1 for Additions, or Type 2 for subtractions: 2 Please select your difficulty level Type 1 for Easy (numbers 1 to 10) Type 2 for Medium (numbers 10 to 100) Type 3 for Hard (numbers 100 to 1000) 1 Here are 5 easy-level subtraction questions, please attempt all: How…arrow_forwardC++ Visual 2019 A particular talent competition has five judges, each of whom awards a score between 0 and 10 to each performer. Fractional scores, such as 8.3, are allowed. A performer's final score is determined by dropping the highest and lowest score received, then averaging the three remaining scores. Write a program that uses this method to calculate a contestant's score. It should include the following functions: void getJudgeData() should ask the user for a judge's score, store it in a reference parameter variable, and validate it. This function should be called by main once for each of the five judges. void calcScore() should calculate and display the average of the three scores that remain after dropping the highest and lowest scores the performer received. This function should be called just once by main and should be passed the five scores. The last two functions, described below, should be called by calcScore, which uses the returned information to determine which of the…arrow_forwardJava - Painting a Wallarrow_forward
- Problem: A small company needs an interactive program to compute an employee’s paycheck. The payroll clerk will initially input the data, and given the input data, an employee's wage for the week should be displayed on the screen for the payroll check. The data for the employee includes the employee's hourly pay rate and the number of hours worked that week. Wage is equal to the employee's pay rate times the number of hours worked (up to 40 hours). If the employee worked more than 40 hours, wage is equal to the employee's pay rate times 40 hours plus 1½ times the employee's pay rate times the number of hours worked above 40. Instructions: Match the action at the left-side with the correct step number at the right-side (the attached picture). Note that it may be possible to group more than one related actions in the same logical step / process without altering the essence of the algorithm. In the program flow, input and checking of hourly pay rate should come before that of the number…arrow_forward5. A prime number is a number that is only evenly divisible by itself and 1. For example, the number 5 is prime because it can only be evenly divided by 1 and 5. The number 6, how- ever, is not prime because it can be divided evenly by 1, 2, 3, and 6. Write a Boolean function named is_prime which takes an integer as an argument and returns true if the argument is a prime number, or false otherwise. Use the function in a program that prompts the user to enter a number then displays a message indicating whether the number is prime. 6. In another program, use the function you wrote in question 5 to print the prime numbers between 1 and 100 using for loop.arrow_forwardPredefined Function: ceil(), floor(), rand(), srand0 1. Create a program that will round off a given number. Example Program Output: Enter a number to be round of: 10.5 Round off value: 10 Enter a number to be round of: 10.6 Round off value: 11 Enter a number to be round of: 10.4 Round off value: 10 Enter a number to be round of: 11.5 Round off value: 12arrow_forward
- Microwaves / Radio Waves If a scientist knows the wavelength of an electromagnetic wave she can determine what type of radiation it is. Write a program that asks for the wavelength in meters of an electromagnetic wave and then displays what that wave is according to the following chart. (For example, a wave with a wavelength of 1E-10 meters would be an X-ray.) 1x 10-11 1 x 10-8 4 x 10-7 7x 10-7 1x 10-3 1 x 10-2 Gamma Rays. X Rays Ultraviolet Visible Light Infraredarrow_forwardJAVA:arrow_forwardpython language : complete the formula COde with comments and output screenshot is must. No plagarism pleasearrow_forward
- LISP Function help please A function that generates a random day of the week, then displays a message saying that "Today is ... and tomorrow will be ...". Then use the built-in function random first to generate a number between 0 and 6 (including). The expression (random) by itself generates a random integer. You can call it with one parameter to return a value within the range from 0 to the value of the parameter-1. For example, (random 10) will return a value between 0 and 9. Next, use the number generated at the previous step to retrieve the symbol for the day of the week from the list. Use the built-in elt. Extract the symbol-name of the day first, then apply the built-in function capitalize to it. Use the result in the princ function call, and do the same thing for the next day. Make the function return true (t) instead of the last thing it evaluates, to avoid seeing the message printed more than once.arrow_forward1. A prime number is a number that is only evenly divisible by itself and 1. For example, the number 5 is prime because it can only be evenly divided by 1 and 5. The number 6, however, is not prime because it can be divided evenly by 1, 2, 3, and 6.Write a Boolean function named is_prime which takes an integer as an argument and returns true if the argument is a prime number, or false otherwise. Use the function in a program that prompts the user to enter a number then displays a message indicating whether the number is prime.Tip:Recall that the % operator divides one number by another and returns the remainder of the division. In an expression such as num1 % num2, the % operator will return 0 if num1 is evenly divisible by num2.arrow_forwardUse C Language Airline Reservation System A small airline has just purchased a computer for its new automated reservations system. The president has asked you to program the new system. You are to write a program to assign seats on each flight of the airline's only plane (capacity: 10 seats). Your program should display the following menu of alternatives: Please type 1 for "first class" Please type 2 for "economy" If the person types 1, then your program should assign a seat in the first class section (seats 1-5). If the person types 2, then your program should assign a seat in the economy section (seats 6-10). Your program should then print a boarding pass indicating the person's seat number and whether it is in the first class or economy section of the plane. Use a single-subscripted array to represent the seating chart of the plane. Initialize all the elements of the array to 0 to indicate that all seats are empty. As each seat is assigned, set the corresponding elements of…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr