UCSD Create a Variable and Set It to A Single Quoted String Value Question
Description
In main.py
, create a variable named first_name
and set it to a single-quoted string value containing your first name.
Add a variable named last_name
and set it to a double-quoted string containing your last name.
- Add a variable named
full_name
and set it to thefirst_name
variable concatenated with thelast_name
variable, adding a space in the middle.
Add a print()
below your variable declaration that outputs the value of the full_name
variable to the terminal.
Check it by running the Python file.
- You should see your full name printed in the terminal window, on the same line.
Create a variable height_in_inches
and assign it your height as an integer.
- Add a single
print()
below your variable declaration that outputs both the value and type of theheight_in_inches
variable.
Create a variable height_in_inches_float
and assign it the value of the height_in_inches
variable, converted to a floating point number.
Add a single print()
below your variable declaration that outputs both the value and type of the height_in_inches_float
variable.
Check it by running the Python file and verifying both the number and type are printed, and that the type is a float
- Create a variable
height_in_meters
and assign it the value of theheight_in_inches_float
variable, converted into the matching units:
2.54
centimeters is equal to 1.0
inch.
1.0
meter is equal to 100.0
centimeters.
Add a single print()
below your variable declaration that outputs the value of height_in_meters
.
- Check it by running the Python file and verifying the number is printed.
- Run the same conversion in a calculator to double-check the value is correct.
height_in_meters
should have a smaller value thanheight_in_inches
.
- Create a variable
eats_plants
and assign it the valueTrue
.
Create a variable eats_animals
and assign it the value False
.
- Read the following sections of Python Operators.
Python Comparison Operators
Python Logical Operators
- Create a variable
is_animal
and, using theor
operator and both theeats_plants
&eats_animals
variables, assign it:
True
if either eats_plants
or eats_animals
are True
.
False
otherwise.
- Create a variable
is_omnivore
and, using theand
operator and both theeats_plants
&eats_animals
variables, assign it:
True
if both eats_plants
and eats_animals
are True
.
False
otherwise.
Create a variable is_plant
and, using the not
operator and the is_animal
variable, assign it the opposite of the value is is_animal
.
- Add a single
print()
that outputs the values ofis_animal
,is_omnivore
, andis_plant
. Run the Python file and verify all three have the correct values.
Create the following variables:
mean_height_in_meters
: set to1.7155
.
short_threshold_in_meters
: set to 1.576
.
tall_threshold_in_meters
: set to 1.860
.
Derive the following boolean values from the above variables:
is_mean_height
:height_in_meters
is exactly equal tomean_height_in_meters
.
is_short
: height_in_meters
is less than short_threshold_in_meters
.
is_tall
: height_in_meters
is greater than or equal to tall_threshold_in_meters
.
is_normal_height
:height_in_meters
is greater than or equal toshort_threshold_in_meters
and less thantall_threshold_in_meters
.
Add a single print()
that outputs the values of is_mean_height
, is_short
, is_tall
, and is_normal_height
. Run the Python file and verify all four have the correct values.
Create a variable nothing
and assign it the value None
.
- Add a single
print()
below your variable declaration that outputs both the value and type of thenothing
variable. Run the Python file and examine its output.
Example Result
Have a similar assignment? "Place an order for your assignment and have exceptional work written by our team of experts, guaranteeing you A results."