Question: Variables and types Open a python interpreter and write the instructions in the following block list. Please note that the examples are indeed examples. Therefore,

Variables and types

Open a python interpreter and write the instructions in the following block list. Please note that the examples are indeed examples. Therefore, you should use different values doing your code, do not copy-paste, or you will get errors.

Create a string, e.g., my_string=Hello Jeddah. Print the variable.

Create a string that contains the text representing a number, e.g., number_string=22. Test the type of the variable, e.g., type(number_string). Print the variable.

Get a integer from the previous string, e.g., my_integer=int(number_string). Test the type of the variable, e.g., type(my_integer). Print the variable.

Get a floating from the previous string, e.g., my_floating=float(number_string). Test the type of the variable, e.g., type(my_floating). Print the variable.

Get a string from the previous floating number, e.g., my_new_string=str(my_floating). Test the type of the variable, e.g., type(my_floating). Print the variable.

Get an integer from a floating number, e.g., int(22.3). Print the variable.

Eval a string to get a number, e.g., my_eval=eval(23.8). Test the type of the variable, e.g., type(my_eval). Print the variable.

Eval a new string to get a number, e.g., my_eval2=eval(23). Test the type of the variable, e.g., type(my_eval2). Print the variable. The function eval gave a different type of variable. Say why.

Reply below:

Try to get an integer from the first string, e.g., my_integer_fail=int(my_string). Then, say why the operation failed.

Reply below:

Try to print the integer you were trying to get from a string, e.g., print(my_integer_fail). It does not work. Explain why.

Reply below:

Create a Boolean variable with the value False, e.g., my_bool=False. Print its value. Make a string from that variable with the str operator, e.g., my_false=str(my_bool). Note that the string is not the same as the Boolean variable. Test this concept with:

my_bool == my_false

my_bool != my_false

To finalize this part, attach a screenshot of your computer.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!