WGU Python D522
Print (10 > 9)
print(10 == 9)
print (10 < 9) - answer Boolean
print(bool("Hello"))
print(bool("15"))
print(bool(x)) - answer Boolean examples of True
print(bool(False))
print( )
print(0) - answer Boolean examples of False
print(isinstance(x, int)) - answer determine if an object is of a certain data type
int( ) - answercasts an integer from an integer literal, float literal, or string literal
float( ) - answercasts a float from an integer literal, a float literal, or a string literal
str( ) - answercasts a string from strings, integer literals, or a float literals
print("text") - answeroutputs text to the console
print("text", end=" ")
print("more text") - answerwill end with a space and continue on the same line ("text
more text")
print("Wage", wage) - answercomma will print both items with a space between them
print(variable) - answerprints the value of the variable
print("1\n2\n3") - answerprint using newline characters
print( ) - answerprint a blank line
python file.py - answerrun a script file
random function - answerthere is no random function, but there is a random module
(import random)
for x in "bananas":
print(x) - answerstrings are arrays, so this will loop through the characters in "bananas"
, variable=input( ) - answerassign text entered by the user to a variable; input is always a
string
variable = int(input) - answerconvert user input into an integer
hourly_wage = int(input("Enter hourly wage: ")) - answerdisplay text prompt (Enter
hourly wage) to request input from user and convert to integer
print(a.upper( )) - answerdisplay a in console in upper case
print(a.lower( )) - answerdisplay a in console as lower case
print(a.strip( )) - answerremove whitespace at beginning and end
print(a.replace("H", "J")) - answerreplace a string with another string
print(a.split("b")) - answersplit string at specified character
c=a+b
print(c) - answerconcatenate (combine) two strings
a=(f"My name is John, I am {age}")
print(a) - answerf-string; { } is the placeholder/modifier
a = 85.8756
b = format(a, ".2f")
print(b) - answermodifier to format the value to 2 decimal places (85.88)
price = 85.87562649
b = f"Price: ${price:.2f}"
print(b) - answerf-string with placeholder for price and modifier to format value to 2
decimal places (Price: $85.88)
What built-in data type is used when you assign text to your variable? - answerstr
x = "Hello, World!"
x = str("Hello, World!")
What built-in data type is used when you assign a numeric value to your variable? -
answerint
x = 20
x = int(20)
float
x = 20.5
x = float(20.5)
Print (10 > 9)
print(10 == 9)
print (10 < 9) - answer Boolean
print(bool("Hello"))
print(bool("15"))
print(bool(x)) - answer Boolean examples of True
print(bool(False))
print( )
print(0) - answer Boolean examples of False
print(isinstance(x, int)) - answer determine if an object is of a certain data type
int( ) - answercasts an integer from an integer literal, float literal, or string literal
float( ) - answercasts a float from an integer literal, a float literal, or a string literal
str( ) - answercasts a string from strings, integer literals, or a float literals
print("text") - answeroutputs text to the console
print("text", end=" ")
print("more text") - answerwill end with a space and continue on the same line ("text
more text")
print("Wage", wage) - answercomma will print both items with a space between them
print(variable) - answerprints the value of the variable
print("1\n2\n3") - answerprint using newline characters
print( ) - answerprint a blank line
python file.py - answerrun a script file
random function - answerthere is no random function, but there is a random module
(import random)
for x in "bananas":
print(x) - answerstrings are arrays, so this will loop through the characters in "bananas"
, variable=input( ) - answerassign text entered by the user to a variable; input is always a
string
variable = int(input) - answerconvert user input into an integer
hourly_wage = int(input("Enter hourly wage: ")) - answerdisplay text prompt (Enter
hourly wage) to request input from user and convert to integer
print(a.upper( )) - answerdisplay a in console in upper case
print(a.lower( )) - answerdisplay a in console as lower case
print(a.strip( )) - answerremove whitespace at beginning and end
print(a.replace("H", "J")) - answerreplace a string with another string
print(a.split("b")) - answersplit string at specified character
c=a+b
print(c) - answerconcatenate (combine) two strings
a=(f"My name is John, I am {age}")
print(a) - answerf-string; { } is the placeholder/modifier
a = 85.8756
b = format(a, ".2f")
print(b) - answermodifier to format the value to 2 decimal places (85.88)
price = 85.87562649
b = f"Price: ${price:.2f}"
print(b) - answerf-string with placeholder for price and modifier to format value to 2
decimal places (Price: $85.88)
What built-in data type is used when you assign text to your variable? - answerstr
x = "Hello, World!"
x = str("Hello, World!")
What built-in data type is used when you assign a numeric value to your variable? -
answerint
x = 20
x = int(20)
float
x = 20.5
x = float(20.5)