Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Exam (elaborations)

WGU C859 Python Syntax- Questions and Answers (Latest Update ) Already Passed

Rating
-
Sold
-
Pages
11
Grade
A+
Uploaded on
14-12-2024
Written in
2024/2025

WGU C859 Python Syntax- Questions and Answers (Latest Update ) Already Passed print "Hello, world!" A print statement is the easiest way to get your Python program to communicate with you. Being able to command this communication will be one of the most valuable tools in your programming toolbox. - Answers There are two different Python versions. Both Python 2 and Python 3 are used throughout the globe. The most significant difference between the two is how you write a print statement. In Python 3, print has parentheses. print("Hello World!") print("Deep into distant woodlands winds a mazy way, reaching to overlapping spurs of mountains bathed in their hill-side blue.") In this course we will be using Python 2. If you go on to write Python 3 it will be useful to note this key difference. - Answers Text in Python is considered a specific type of data called a string. A string, so named because they're a series of letters, numbers, or symbols connected in order — as if threaded together by string. Strings can be defined in different ways: - Answers print "This is a good string" print 'You can use single quotes or double quotes for a string' While double-quotes (") and single-quotes (') are both acceptable ways to define a string, a string needs to be opened and closed by the same type of quote mark. We can combine multiple strings using +, like so: print "This is " + "a good string" This code will print out "This is a good string". - Answers Try adding your name to the print statement with the + operator so that this Python program prints "Hello [your_name]" - Answers print "Hello " + "Jennifer" Here are some common errors that we might run into when printing strings: print "Mismatched quotes will cause a SyntaxError' print Without quotes will cause a NameError If the quotes are mismatched Python will notice this and inform you that your code has an error in its syntax because the line ended (called an EOL) before the double-quote that was supposed to close the string appeared. The program will abruptly stop running with the following message: SyntaxError: EOL while scanning a string literal - Answers This means that a string wasn't closed, or wasn't closed with the same quote-character that started it. Another issue you might run into is attempting to create a string without quotes at all. Python treats words not in quotes as commands, like the print statement. If it fails to recognize these words as defined (in Python or by your program elsewhere) Python will complain the code has a NameError. This means that Python found what it thinks is a command, but doesn't know what it means because it's not defined anywhere. - Answers Python uses variables to define things that are subject to change. - Answers greeting_message = "Welcome to Codecademy!" current_excercise = 5 In the above example, we defined a variable called greeting_message and set it equal to the string "Welcome to Codecademy!". It also defined a variable called current_exercise and set it equal to the number 5. - Answers Create a variable called todays_date and assign a value that will represent today's date to that variable. todays_date = "March 31, 2023" - Answers Python also offers a companion to division called the modulo operator. The modulo operator is indicated by % and returns the remainder after division is performed. - Answers is_this_number_odd = 15 % 2 is_this_number_divisible_by_seven = 133 % 7 In the above code block, we use the modulo operator to find the remainder of 15 divided by 2. Since 15 is an odd number the remainder is 1. We also check the remainder of 133 / 7. Since 133 divided by 7 has no remainder, 133 % 7 evaluates to 0. - Answers 1. Multiply two numbers together and assign the result to a variable called product. - Answers product = 2 * 2 . What is the remainder when 1398 is divided by 11? Save the results in a variable called remainder. Hint Remember that remainders can be found using the modulus operator. Calculate a remainder with %. - Answers remainder = 1398 % 11 Changing the contents of a variable is one of the essential operations. As the flow of a program progresses, data should be updated to reflect changes that have happened. - Answers fish_in_clarks_pond = 50 print "Catching fish" number_of_fish_caught = 10 fish_in_clarks_pond = fish_in_clarks_pond - number_of_fish_caught - Answers In the above example, we start with 50 fish in a local pond. After catching 10 fish, we update the number of fish in the pond to be the original number of fish in the pond minus the number of fish caught. At the end of this code block, the variable fish_in_clarks_pond is equal to 40. Updating a variable by adding or subtracting a number to the original contents of the variable has its own shorthand to make it faster and easier to read. - Answers money_in_wallet = 40 sandwich_price = 7.50 sales_tax = .08 * sandwich_price sandwich_price += sales_tax money_in_wallet -= sandwich_price In the above example, we use the price of a sandwich to calculate sales tax. After calculating the tax we add it to the total price of the sandwich. Finally, we complete the transaction by reducing our money_in_wallet by the cost of the sandwich (with tax). We're trying to figure out how much it rained in the past year! Update the annual_rainfall variable to include the values from September to December. - Answers january_to_june_rainfall = 1.93 + 0.71 + 3.53 + 3.41 + 3.69 + 4.50 (I added the below) september_to_december_rainfall = 5.16 + 7.20 +5.06 + 4.06 annual_rainfall = january_to_june_rainfall + september_to_december_rainfall july_rainfall = 1.05 annual_rainfall += july_rainfall august_rainfall = 4.91 annual_rainfall += august_rainfall september_rainfall = 5.16 october_rainfall = 7.20 november_rainfall = 5.06 december_rainfall = 4.06

Show more Read less
Institution
WGU C859 Python Syntax
Course
WGU C859 Python Syntax

Content preview

WGU C859 Python Syntax- Questions and Answers (Latest Update 2024-2025) Already Passed

print "Hello, world!"



A print statement is the easiest way to get your Python program to communicate with you. Being able to
command this communication will be one of the most valuable tools in your programming toolbox. -
Answers

There are two different Python versions. Both Python 2 and Python 3 are used throughout the globe.
The most significant difference between the two is how you write a print statement. In Python 3, print
has parentheses.



print("Hello World!")

print("Deep into distant woodlands winds a mazy way, reaching to overlapping spurs of mountains
bathed in their hill-side blue.")



In this course we will be using Python 2. If you go on to write Python 3 it will be useful to note this key
difference. - Answers

Text in Python is considered a specific type of data called a string. A string, so named because they're a
series of letters, numbers, or symbols connected in order — as if threaded together by string. Strings can
be defined in different ways: - Answers print "This is a good string"

print 'You can use single quotes or double quotes for a string'



While double-quotes (") and single-quotes (') are both acceptable ways to define a string, a string needs
to be opened and closed by the same type of quote mark.

We can combine multiple strings using +, like so:

print "This is " + "a good string"

This code will print out "This is a good string". - Answers

Try adding your name to the print statement with the + operator so that this Python program prints
"Hello [your_name]" - Answers print "Hello " + "Jennifer"

Here are some common errors that we might run into when printing strings:

, print "Mismatched quotes will cause a SyntaxError'

print Without quotes will cause a NameError



If the quotes are mismatched Python will notice this and inform you that your code has an error in its
syntax because the line ended (called an EOL) before the double-quote that was supposed to close the
string appeared. The program will abruptly stop running with the following message:



SyntaxError: EOL while scanning a string literal - Answers This means that a string wasn't closed, or
wasn't closed with the same quote-character that started it.

Another issue you might run into is attempting to create a string without quotes at all.

Python treats words not in quotes as commands, like the print statement.

If it fails to recognize these words as defined (in Python or by your program elsewhere) Python will
complain the code has a NameError. This means that Python found what it thinks is a command, but
doesn't know what it means because it's not defined anywhere. - Answers

Python uses variables to define things that are subject to change. - Answers

greeting_message = "Welcome to Codecademy!"

current_excercise = 5



In the above example, we defined a variable called greeting_message and set it equal to the string
"Welcome to Codecademy!". It also defined a variable called current_exercise and set it equal to the
number 5. - Answers

Create a variable called todays_date and assign a value that will represent today's date to that variable.



todays_date = "March 31, 2023" - Answers

Python also offers a companion to division called the modulo operator. The modulo operator is
indicated by % and returns the remainder after division is performed. - Answers

is_this_number_odd = 15 % 2

is_this_number_divisible_by_seven = 133 % 7

Written for

Institution
WGU C859 Python Syntax
Course
WGU C859 Python Syntax

Document information

Uploaded on
December 14, 2024
Number of pages
11
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

$8.89
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
TutorJosh Chamberlain College Of Nursing
Follow You need to be logged in order to follow users or courses
Sold
433
Member since
1 year
Number of followers
17
Documents
31621
Last sold
16 hours ago
Tutor Joshua

Here You will find all Documents and Package Deals Offered By Tutor Joshua.

3.5

73 reviews

5
26
4
16
3
14
2
1
1
16

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions