Site icon Tutor Bin

UCSD Create a Variable and Set It to A Single Quoted String Value Question

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.

  1. Add a variable named full_name and set it to the first_name variable concatenated with the last_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.

  1. 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.

  1. Add a single print() below your variable declaration that outputs both the value and type of the height_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

  1. Create a variable height_in_meters and assign it the value of the height_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 than height_in_inches.
  1. Create a variable eats_plants and assign it the value True.

Create a variable eats_animals and assign it the value False.

  1. Read the following sections of Python Operators.

Python Comparison Operators

Python Logical Operators

  1. Create a variable is_animal and, using the or operator and both the eats_plants & eats_animals variables, assign it:

True if either eats_plants or eats_animals are True.

False otherwise.

  1. Create a variable is_omnivore and, using the and operator and both the eats_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 of is_animal, is_omnivore, and is_plant. Run the Python file and verify all three have the correct values.

Create the following variables:

  1. mean_height_in_meters: set to 1.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 to mean_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 to short_threshold_in_meters and less than tall_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.

  1. Add a single print() below your variable declaration that outputs both the value and type of the nothing 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."

Exit mobile version