Data Type & Variables

(Expected time: 30 mins)

  1. Give a command that displays your introduction in 3 lines.

Solution
print('Hello, i am Dave')
print('I am learning Data Science from Console flare')
print('This is my first assignment')
  1. Write a program and create a variable, store an integer value in it, and print the value.

  2. Write a program and create three variables called name, age, and company then store your name, your age, and your company's name in it, and

  • Print your name, age, and company.

  • Now display the message "After 5 Years".

  • Now you have switched to another company. Update the company variable and display your new company.

  1. Declare a variable and store the value of pi in it. Display the value and check the type of it.

Solution
x=3.14159265
print(x,type(x))
  1. Write a program to create two variables a and b which have 2 and 3 as data stored in them. Now create a program that swaps the data which means the data stored in a is 3 and data stored in b is 2. (WITH THE HELP OF A THIRD VARIABLE).

Solution
a=2 
b=3
c=a    # Take a third variable that holds the value of a. c=2
a=b    # a=3
b=c    # b=2
print(a,b)
  1. Write a program to create two variables a and b which have 5 and 10 as data stored in them. Now create a program that swaps the data which means the data stored in a is 10 and data stored in b is 5. (WITHOUT USING A THIRD VARIABLE).

Solution
a=5
b=10
a=a+b  # now a is 15      
b=a-b  # now b is 5
a=a-b  # now a is 10
print(a,b)
  1. What is wrong in this code snippet? a,b,c=1,2

  • Nothing is wrong

  • The value of c is missing

  • Wrong syntax

  • None of the above

Solution

Value of c is missing.

  1. a,b,c=22,33,78 print(a,c) What will be the output of this code?

  • 22,78

  • 22,33,78

  • 33,78

  • 22,33

Solution

22,78

  1. You have to create three variables A, B, and C. Store 2000 in all of them. This task can be done by two methods: a. A=B=C=2000 b. A, B, C=2000,2000,2000 c. a and b both d. None of the above e. A, B, C=2000

Solution

c

  1. What will be the output of the following code? x = 10 y = 5.5 z = "10" print(type(x), type(y), type(z))

Solution
<class 'int'> <class 'float'> <class 'str'>
  1. Check the data type of the following: a. 2+3 b. '56+78' c. 'True + False * 0' d. 32+0.0 e. 7834+57.23

Solution
print(type(2+3))
print(type('56+78'))
print(type( 'True + False * 0'))
print(type(32+0.0))
print(type(7834+57.23))

Last updated