STD 6
STD 6
Q.Trace the following source code and find out the outputs:
a.Code:
var1 = input ('Enter the first variable:')
var2 = input ('Enter the second variable:')
temp = var1
var1 = var2
var2 = temp
print ('The value of the first variable after swapping:', var1)
print ('The value of the second variable after swapping:', var2)
Output:
b. Code:
#This is a simple program
#to output simple statements
#print(“Such as”)
print(“Take every chance”)
print(“Drop every fear”)
Output:
c. Code:
a=int(input(“input the 1st value:”))
b=int(input(“input the 2nd value:”))
s=a+b
print(“The sum=”,s)
Output:
Q. Use the code to answer the following questions:
1. Value1=5.1
2. Value2=678
3. ABC="Bangladesh"
4. DCE="Apple"
5. print( Value1+8)
6. print( ABC,"=",DCE)
7. print( Value2)
8. print( "Value1"+"8")
9. print( "Value1"+"Value2")
a. What data type are each of the variables? b. Write what each line will print out:
i. num_1: i. Line5:
ii. num_2: ii. Line 6:
iii. Line 7:
iii. food_1:
iv. Line 8:
iv. food_2 : v. Line 9:
Q. Rewrite the following code in Python after removing all errors and in order to get the output.
a.Code:
PI=3.14
radius = float(input("Enter the radius of the circle: ")
area = PI * (radius ** 2)
perimeter = 2 * PI * radius
print("Area of the circle:" area)
print("Perimeter of the circle:",perimete)
Correct code:
Output:
b. Code:
Side=int(input("Enter the value of Side:")
Area=side*side
Perimeter= 4*Side
print("Perimeter of a Square:", perimeter)
print("Area of a Square:" Area)
Correct Code:
Output:
Q. Sort the given program:-
a.Code:
Perimeter= 2*(Length+Width)
Length=int(input("Enter the the value of Length:"))
Area=Length*Width
print("Perimeter of a Rectangle:", Perimeter)
print("Area of a Rectangle:", Area)
Width=int(input("Enter the the value of Width:"))\
Correct code:
Output:
c.Code:
print("Perimeter of a Triangle :", Perimeter)
Area=1/2*(Base* Height)
Side2=int(input("Enter the value of Side2:"))
Base=int(input("Enter the value of Base:"))
Height=int(input("Enter the value of Height:"))
Side1=int(input("Enter the value of Side1:"))
print("Area of a Triangle :", Area)
Side3=int(input("Enter the value of Side3:"))
Perimeter= Side1+Side2+Side3
Output:
2. a = 10 Ans:
b = 20
print(a+b) 5. x = 10
print ('a+b') y = 20
print(x>=y)
Output:- 1020/30 a+b / 'a+b'/abc
Output:- True/ False/both 0 and 1/ 1
Ans:
Ans:
3. a =10100
b =10100
print(a & b)
Ans: