Python is flexible about variable declaration. You do not need to give data type of a variable at the time of it’s declaration. a=5 (We can say here that “a” stores the integer 5.) Valid:defined a variable ‘a’ and passed a value of 5 to it. This statement has three parts: 1. Variable name 2. Assignment operator 3. Variable value A program is essentially a manipulation of data. The logic is what you code. The variables hold the data. Operators act on variables.Perimeter of a circle
Input: Radius (int or float) Logic: 2 * Pi * Radius Output: float Lessons: 1. How to declare a variable? 2. How to use operators on it?In Code
# Variable declaration. r is holding the radius. r = input("Enter the radius: ") # input() gives you a string r = float(r) # Type casting builtin for getting the float value of r perimeter = 2 * 3.14 * r # Computation print(perimeter)Problems
# 1 Declare two integer variables. And perform arithematic operations on them. # 2 Take two user inputs: dividend and divisor. Now perform division on them. #3 Take input. Name: Radius Calculate: Perimeter of the circle. Area of the circle. HINT: Step 1: declare a variable to take user input Step 2: declare a second variable Pi. Step 3: use the above two variables in formula to find the perimeter. #4 1. Take two integers as input. 2. Show if they are equal or unequal. #5 1. Take three inputs. Name them length, width and height 2. Find the volume of the cuboid. 3. Find the area of this cuboid. = 2*l*w + 2*w*h + 2*l*h #6 1. Take an integer as input. Name it 'side'. 2. Print the volume of the cube. 3. Print the surface area of the cube. #7 Find the area of the equilateral triangle.Solutions
x = 4 y = 9 x + y x - y dividend = 8 divisor = 2 dividend / divisor import math radius = 5 perimeter = 2 * math.pi * radius area = math.pi * radius * radius a = 7 b = 8 print(a == 8) l = 5 w = 7 h = 9 v = l * w * h print(v) 315 2*l*w + 2*w*h + 2*l*h 286 side = 5 area = math.sqrt(3) * pow(side, 2) / 4 print(area) 10.825317547305483
Friday, April 21, 2023
7 Problems on Operators and Variables
Labels:
Python,
Technology
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment