Variables Code#

Please solve the following questions using Python code.
Question-1#
Create a variable named course and assign the value math to it.
Solution
course = 'math'
Question-2#
Create a variable named weight and assign the value 180.4 to it.
Solution
weight = 180.4
Question-3#
Create a variable named number_of_apples and assign the value 45 to it.
Solution
number_of_apples = 45
Question-4#
Write the code to convert the integer 1 to the string '1'
Solution
str(1)
Question-5#
Create a variable named
xand assign the value 7 to it.Create a variable named
yand assign the value 3 to it.Display the sum, difference, and product of 7 and 3 using the variables
xandy.
Solution
x = 7
y = 3
print('Sum :', x+y)
print('Difference :', x-y)
print('Product :', x*y)
Question-6#
Create a variable named
xand assign the value 7 to it.Create a variable named
yand assign the value 3 to it.Create a variable named
z, assign the value ofx * yto it.Display
z.
Solution
x = 7
y = 3
z = x*y
print('Product :', z)
Question-7#
Create a variable named
widthand assign the value10to it.Create a variable named
lengthand assign the value50to it.These variables represent the sides of a rectangle.
Create a variable named
perimeterand assign the value of the rectangle’s perimeter to it.Create a variable named
areaand assign the value of the rectangle’s area to it.Display the following statements by using the variables
width,length,perimeterandarea.The width of the garden is 10 ft.
The length of the garden is 50 ft.
The area of the rectangle is 500 square ft, indicating a large size.
The perimeter of the rectangle measures 120 ft, indicating that a considerable amount of fencing is required.
Please avoid using the numbers 10 and 50 in your code, and remember to include appropriate punctuation.
Solution
width = 10
length = 50
perimeter = 2*(width+length)
area = width*length
print('The width of the garden is '+str(width)+' ft.')
print('The length of the garden is '+str(length)+' ft.')
print('The area of the rectangle is '+str(area)+' square ft, indicating a large size.')
print('The perimeter of the rectangle measures '+str(perimeter)+' ft, indicating that a considerable amount of fencing is required.')
Question-8#
Create a variable named
xand assign the value3to it. (integer type)Without directly using the number
3in your code (use variablex) print3333using three different codeAssign 5 to x and verify if you obtain
5555with the same code.
Solution
x = 3
print(str(x)*4)
print(str(x)+str(x)+str(x)+str(x))
print(x*1111)
print('-'*4)
x = 5
print(str(x)*4)
print(str(x)+str(x)+str(x)+str(x))
print(x*1111)