Type A : Short Answers Questions
1. What are data types? How are they important?
Answer = representation of many types of data in by provided facilities is called data type .
Example = integer, string , list etc.
They are play very important role in programming because without any data of program ,
program can cause error , so program needed data .
2. How many integer types are supported by Python? Name them.
Answer= tow type of integer are supported by python
(I)Integer (signed)
(II)Booleans
3. How are these numbers different from one another? 33, 33.0, 33j, 33 +j
Answer --
33 = integer
33.0=floating point number
33j = complex number
33+j = complex number
4. How many string types does Python support?How are they different from one another?
Answer =
Answer = two type of string :
(1) single line strings
(2) multiline strings
In single line string , string are in one line and enclosed by single or double quotes, while in
multiple line string ,string are enclosed by triple quotes in multiple line .
5. How many string types does Python support?How are they different from one another?
Answer =
Answer = two type of string :
(1) single line strings
(2) multiline strings
In single line string , string are in one line and enclosed by single or double quotes, while in
multiple line string ,string are enclosed by triple quotes in multiple line
6. What will following code print?
str1 = ‘’’Hell
o’’'
str2 = ‘’’Hell \
o’’’
print (len(str1)>len(str2))
Answer =
True
Because : Str1 = hell\no
Str2 = hello
7. What are immutable and mutable types? List immutable and mutable types of python.
Answer = immutable type :- those types whose value never change is known as immutable type.
Example = integer , string , Boolean, tuples , e.c.t
Mutable type: - those type whose value can be change is known as mutable type.
Example = list, dictionary, set
8. What are three internal key-attributes of a value-variable in Python Explain with example.
Answer = (1)A type :-
It determined the type of object by using function type()
Example = >>>a = 5
>>>type(a)
<class ‘int’>
(2)A value :-
It is data item contained in the object .it can use by print statement.
Example = >>>a = “python”
>>>print (a)
‘python’
(3) the id :-
It refers the memory location of the object. It can use by function id ()
Example = >>>a = 8
>>>id (a)
308829545
9. Is it true that if two objects return True for is operator, they will also return True for ==
operator?
Answer = yes, it is always true.
10. Are these values equal? Why/why not?
(i) 20 and 20.0
(ii) 20 and int(20)
(iii) str(20) and str(20.0)
(iv) 'a' and "a”
Answer =
(i) according to == operator it is True. But according to is operator it is not True, because due to
different memory location.
(ii) According to == and is operator it is True because of same memory location.
(iii) here it is False for == and is operator because of different length of string .
(iv) according to == and is operator it is True , because of same memory location .
11. What is an atom ? What is an expression?
Answer =
Atom :- something that has a value .
Example = identifiers, list , tuples , strings , literals
Expression :- an expression in python is any valid combination of operators and atoms.
12. What is the difference between implicit type conversion and explicit type conversion?
Answer = the basic difference between implicit and explicit type conversion is that implicit is
taken care by compiler itself , while explicit is done by the programmer .
13 Two objects (say a and b) when compared using ==, return True. But Python gives False
when compared using is operator. Why
(i.e, a == b is True but why is a is b False ?)
Answer =
Because python assign different memory address to a and b even if their exists a same value .
14. Given str1= "Hello", what will be the values of
(a)str1[0]
(b)str1 [1]
(c)str1[-5]
(d)str1[-4]
(e)str1[5]
Answer =
(a) H
(b) e
(c)H
(d)e
(e)index out of range .
15 . If you give the following for str1 = "Hello", why does python report error ?
str1[2] = 'p'
Answer = python report error because string are immutable
16. What will the result given by the following ?
(a)type(6+3)
(b)type(6-3)
(c)type(6*3)
(d)type(6/3)
(e)type(6//3)
(f)type(6%3)
Answer =
(a)int
(b)int
(c)int
(d)float
(e)int
(f)int
17. What are augmented assignment operators ? How are they useful ?
Answer =
it is the combination , in a single statement , of a binary operation and an assignment statement .
Example = c += 5
They are useful because they reduce the length of the code and make it look cleaner
18. Differentiate between (555/222) ** 2 and (555.0/222) **2.
Answer =
Different between them is that in first 555 that is int type , in second 555.0 that is float type
19. Given three Boolean variables a,b, c as : a= False , b = True , c = False.
Evaluate the following Boolean expressions :
(a)b and c
(b)b or c
(c)not a and b
(d)(a and b)or not c
(e)not b and not (a or c)
(f)not ((not b or not a)and c )or a
Answer =
(a)False
(b)True
(c)True
(d)True
(e)False
(f)True
20. What would following code fragments result in ? Given x =3.
(a) 1 <x
(b) x >= 4
(c) x==3
(d) x==3.0
(e) "Hello"== "Hello"
(f) "Hello" > "hello"
(g)4/2==2.0
(h)4/2==2
(i)x <7 and 4>5
Answer =
(a) True
(b) False
(c) True
(d) True
(e) True
(f) False
(g) True
(h) True
(i)False
21.Write following expressions in Python:
Answer -------
(a)(b**2*h)/3
(b) 3.14*r**2*h
(c)(3.14*r**2*h)/3
(d) d = ((x2-x1)**2+(y2-y1)**2)**1/2
(e) (x-h)**2+(y-k)**2 == r**2
(f) x = (-b + (b**2-4*a*c)**1/2)/2*a
(g) a**n * a**m == a**n+m
(h) (a**n)**m==a ** n*m
(i) a**n /a**m = a**n-m
(j) a**(-n)==1/a**n
22. Int(‘a’) produces error. Why?
Answer = Int (‘a’) produces error because here ‘a’ is a sting , while int function is used to change
number from fraction to integer . but here ‘a’ is string so when int function work then it produce
error .
23. Int('a') produces error but following expression having int('a') in it, does not return error.
Why?
len(‘a’) 2 or int('a')
Answer =
Because first expression is True , so or operator will not check next operands .
so for this expression will not produce error .
24. Write expression to convert the values 17, len('ab') to
(i) = integer (ii) str (ii) Boolean values
Answer =
(i) int (17) , int (len(‘ab’))
(ii) str(17) , str(len(‘ab’))
(iii) bool(17) , bool(len(‘ab’))
25. Evaluate and Justify
(i) 22/17=37/47+88/83 (ii) len(375)**2.
Answer =
(i) it produce error because here 22/7 is variable and we know that number can not be use in
variable .
(ii)it produce answer 9 , first len function find the length of string then squaring of 3 then give
the answer .
26. Evaluate :
(i) 22.0/7.0 - 22/7(ii)22.0/7.0-int(22.0/7.0)
(iii)22/7-int(22.0)/7 and justify
Answer =
(i) 22.0/7.0 - 22/7
>>> 0.0
(ii)22.0/7.0-int(22.0/7.0)
>>>0.1428571428571428
(iii)22/7-int(22.0)/7
>>>0.1428571428571428
27. Evaluate and justify :
(a) 0 or None and "or"
(b) 1 or None and 'a' or 'b
(c) False and 23
(d) 23 and False
(e) not (1 == 1 and 0 != 1)
(f)("abc" =="Abc" and not (2 == 3 or 3 == 4)
(g) False and 1 == 1 or not True or 1 ==1 and False or 0==0
Answer =
(a)>>>
(b) 1
(c) False
(d) False
(e) False
(f) False
(g)True
28. Evaluate and justify :
(a) 0 or None and "or"
(b) 1 or None and 'a' or 'b
(c) False and 23
(d) 23 and False
(e) not (1 == 1 and 0 != 1)
(f)("abc" =="Abc" and not (2 == 3 or 3 == 4)
(g) False and 1 == 1 or not True or 1 ==1 and False or 0==0
Answer =
(a)>>>
(b) 1
(c) False
(d) False
(e) False
(f) False
(g)True
29. Evaluate the following for each expression that is successfully evaluated, determine its value
and type for unsuccessful expression, state the reason.
(a) len("hello") ==25/5 or 20/10
(b) 3<5 or 50/(5 - (3 + 2))
(c) 50/(5 - (3 + 2)) or 3 < 5
(d) 2 *(2 *(len ("01"))).
Answer = (a) True
(b) True
(c) zero division error .
(d) 8
30. Write an expression that uses exactly 3 arithmetic operators with integer literals and produces
result as 99.
Answer =
11*(11+3-5)
31 Add parentheses to the following expression to make the order of evaluation more clear.
y % 4 ==0 and y % 100 != 0 or y % 400 == 0
Answer =
(y % 4 ==0 ) and (y % 100 != 0 ) or (y % 400 == 0 )
32. A program runs to completion but gives an incorrect results. What type of error would have
caused it?
Answer =
Logical error.
33. In Python, strings are immutable while lists are mutable. What is the difference?
Answer =
(i) In consecutive locations, strings store the individual characters while list stores the references
of its elements
(ii) Strings store single type of elements - all characters while lists can store elements belonging
to different types.
34. How does the // operator differ from the / operator? Give an example of where // would be
needed.
Answer =
The // operator is the division in which only the whole part of the result is given in the output and
the fractional part is truncated. While / operator dived the value and give full answer in float
value.
// operator would be needed when we want only integer value.
35. Mid Air Airlines will only allow carry-on bags that are no more than 22 inches long, 14
inches wide, and 9 inches deep. Assuming that variables named length, width, and depth have
already been assigned values, write an expression combining the three that evaluates to True if
bag fits within those limits, and False otherwise.
Answer =
l = int(input("Enter length :-"))
w = int(input("Enter width :-"))
d = int(input("Enter Depth :-"))
print( (l <= 22) and ( w<= 14 ) and (d <= 9) )
36 . What are main error types? Which types are most dangerous and why?
Answer =
Error are three types:-
(i) Compile time error
(ii) Run time error
(iii) Logical error
Logical error are more dangerous, because In spite of logical errors' presence, the program
executes without any problems but the output produced is not correct. Therefore, each and every
statement of the program needs to be scanned and interpreted.
37. Correct any false statements:
(a) Compile-time errors are usually easier to detect and to correct than run-time errors.
(b) Logically errors can usually be detected by the compiler.
Answer =
Option (b) is false statements.
38. Differentiate between a syntax error and a semantics error.
Answer =
Syntax errors are the errors that occur when rules of a programming language are violated. While
Semantics errors occur when statements are not meaningful.
Syntax refers to formal rules governing the construction of valid statements in a language. While
semantics refers to the set of rules which give the meaning of a statement.
39. Differentiate between a syntax error and a logical error in a program. When is each type of
error likely to be found?
Answer =
Syntax errors are the errors that occur when rules of a programming language are violated. While
logical error is an error that occurs due to the fault in the program. At the time of Running
program.
40. What is the difference between an error and exception?
Answer =
Error is a bug in the code that causes irregular output or stops a program from executing. While
an Exception is an irregular unexpected situation occurring during execution on which
programmer has no control.
Type B : Application based Questions
1.What is the result produced by
(i) bool (0)
(ii) bool (str(0)) ? Justify the outcome.
Answer =
(i) False: Integer value 0 has false truth value hence bool() converts it to False.
(ii) True: ‘0’ is string value, which is non-empty string and has a truth value, hence bool()
convert it to True.
2. What will be the output, if input for both the statements is 5+4/2?
6 == input ("Value 1 :")
6 == int(input ("value 2:"))
Answer =
It will give error, because in second line int function cannot convert given input in integer form.
3.Following code has an expression with all integer values. Why is the result in floating point
form?
a, b, c = 2, 3, 6
d=a+b*c/b
print(d)
Answer =
Due to use of ‘/’ division in the program.
4.What will following code print?
(a)
a = va = 3
b = va = 3
print (a, b)
(b)
a=3
b = 3.0
print (a == b)
print (a is b)
Answer =
(a)
Output:
33
(b)
Output:
True
False
5.What will be output produced by following code? State reason for this output.
a, b, c = 1, 1, 2
d=a+b
e = 1.0
f = 1.0
g = 2.0
h=e+f
print(c = d)
print(c is d)
print(g == h)
print(g is h)
Answer =
Output:
True
True
True
False
False: Because python assigns different memory address to floating point values even if there
exists a same value in the memory.
While integer values are bound to same memory address.
6.What will be the output of following Python code?
a = 12
b = 7.4
c=1
a -= b
print(a, b)
a *= 2 + c
print(a)
b += a * c
print(b)
Answer =
Output is:
4.6 7.4
13.799999999999999
21.2
x , y = 4, 8
z = x /y * y
print(z)
Answer =
Output is:
4.0
7.Make change in the expression for z of previous question so that the output produced is zero.
You cannot change the operators and order of variables.
(Hint: Use a function around a sub-expression)
Answer =
x , y = 4, 8
z = x /y * y and 0
print(z)
8. Consider the following expression.
x = "and" * (3 + 2) > "or" + "4"
9.What is the data type of value that is computed by this expression?
Answer =
>>> x = "and" * (3 + 2) > "or" + "4"
>>> x
10.Consider the following code segment:
a = input()
b = int(input())
c=a+b
print(c)
When the program is run, the user first enters 10 and then 5, it gives an error. Find the error, its
reason and correct it.
Answer =
Correct program:-
a = int (input())
b = int(input())
c=a+b
print(c)
Reason:- string value and integer value cannot add.
False
>>> type(x)
<class 'bool'>
>>>
11.Consider the following code segment:
a = input("Enter the value of a:")
b = input("Enter the value of b:")
print(a + b)
If the user runs the program and enters 11 for a and 9 for b then what will the above code
display.
Answer =
Enter the value of a: 11
Enter the value of b: 9
119
>>>
Find out the error and the reason for the error in the following code. Also, give the corrected
code.
a, b = "5.0", "10.0"
x = float (a/b)
print(x)
Answer =
Correct code:-
a, b = 5.0, 10.0
x = float (a/b)
print(x)
Reason:- String value cannot divide. That’s why it give error.
When this program is run, the following output is generated (note that input entered by the user
is shown in bold):
Enter the length of the first side: 3
Enter the length of the second side: 4
Traceback (most recent call last):
h = sqrt(a * a + b * b)
NameError: name 'sqrt' is not defined
Why is this error occurring? How would you resolve it?
Answer =
Because sqrt() function of math module. But in this program math module is not import that’s
why this give an error.
If we import math module then it will give no error.
After adding import math to the code given above, what other change(s) are required in the code
to make it fully work?
Answer =
We have to call math module in program like this:-
Correct program:-
import math
a = float(input("Enter the length of the first side:"))
b = float(input("Enter the length of the second side:"))
h = math.sqrt(a * a + b * b)
print("The length of the hypotenuse is", h)
Which of the following expressions will result in an error message being displayed when a
program containing it is run?
(a) 2.0/4
(b) "3" + "Hello"
(c) 4 % 15
(d) int("5") / float("3")
(e) float("6"/"2")
Answer =
option (e) will give an error.
Following expression does not report an error even if it has a sub-expression with ‘divide by
zero’ problem:
3 or 10/0
What changes can you make to above expression so that Python reports this error?
Answer =
Because ‘or’ operator does not check more, if first value is true.
If we use ‘and’ operator then it will give an error.
What is the output produced by following code?
a, b = bool (0), bool (0.0)
c, d =str (0), str (0.0)
print (len(a), len(b))
print (len(c), len(d))
Answer =
It will give an error that ‘object of type 'bool' has no len()’.
Given a string s = "12345". Can you write an expression that gives sum of all the digits shown
inside string i.e. the program should be able to produce the result as 15 (1 + 2 + 3 + 4 + 5).
[Hint. Uses indexes and convert to integer]
Answer =
s = '12345'
sum = 0
for i in s:
sum = sum + int(i)
print (sum)
Predict the output if ‘e’ is given input as ‘True’
a = True
b=0<5
print (a == b)
print (a is b)
c =str (a)
d = str (b)
print (c == d)
print (c is d)
e = input ("Enter : ")
print (c == e)
print (c is e)
Answer =
True
True
True
True
Enter : True
True
False
Find the errors:
(a)
name = "HariT"
print (name)
name[2] = 'R'
print (name)
(b)
a = bool(0)
b = bool(1)
print (a == false)
print (b == true)
(c)
print (type (int('123')))
print (type(int ("Hello")))
print (type (str("123.0")))
(d)
pi = 3.14
print (type (pi))
print (type ("3.14"))
print (type (float ("3.14")))
print (type (float("three point fourteen")))
(e)
print ("Hello" + 2)
print ("Hello" + '2')
print ("Hello" * 2)
(f)
print ("Hello" / 2)
print ("Hello" / 2)
Answer =
(a)
Error in third line.
(b)
Error in third and fourth line.
(c)
Error in second line that int() function cannot change the string into integer.
(d)
Error in fifth line that float() function cannot change the string into decimal number.
(e)
Error in first line that string cannot added with number.
(f)
Error in both line that string cannot divide with number.
Program is giving a weird result of "0.50.50.50.50.50.50....” Correct it so that it produces the
correct result which is the probability value (input as 0.5) times 150.
probability = input("Type a number between 0 and 1: ")
print("Out of 150 tries, the odds are that only", (probability * 150), "will succeed. ")
[Hint. Consider its datatype.)
Answer =
Correct code :-
probability = int (input("Type a number between 0 and 1: "))
print("Out of 150 tries, the odds are that only", (probability * 150), "will succeed. ")
import random
r = random.randrange (100, 999, 5)
print(r, end = ' ')
r = random.randrange(100, 999, 5)
print(r, end = ' ')
r = random.randrange (100, 999, 5)
print(r)
Which of the following are the possible outcomes of the above code? Also, what can be the
maximum and minimum number generated by line 2?
(a) 655, 705, 220
(b) 380, 382, 505
(c) 100, 500, 999
(d) 345, 650, 110
Answer =
Possible outcomes of the above code is option (a) & (d).
Minimum value:- 100
Maximum value:- 995
22.Consider the code given below:
import random
r = random.randint (10, 100) - 10
print(r, end = ' ')
r = random.randint (10, 100) - 10
print(r, end = ' ')
r = random.randint (10, 100) - 10
print(r)
Which of the following are the possible outcomes of the above code? Also, what can be the
maximum and minimum number generated by line 2?
(a) 12 45 22
(b) 100 80 84
(c) 101 12 43
(d) 100 12 10
Answer =
Option (a) the possible outcomes of the above code.
Max value:- 90
Min value :- 0
23.Consider the code given below:
import random
r= random.random() * 10
print(r, end = ' ')
r = random.random() * 10
print(r, end ='')
r = random.random() * 10
print(r)
Which of the following are the possible outcomes of the above code? Also, what can be the
maximum and minimum number generated by line 2?
(a) 0.5 1.6 9.8
(b) 10.0 1.0 0.0
(c) 0.0 5.6 8.7
(d) 0.0 7.9 10.0
Answer =
Option (a) & (c) are the possible outcomes of the above code.
Max value: - nearly equal to 10, but not 10.
Min value:- 0.0
24.Consider the code given below:
import statistics as st
v = [7, 8, 8, 11, 7, 7]
m1 = st.mean(v)
m2 = st.mode(v)
m3 = st.median(v)
print(m1, m2, m3)
Which of the following is the correct output of the above code?
(a) 7 8 7.5
(b) 8 7 7
(c) 8 7 7.5
(d) 8.5 7 7.5
Answer =
Option (c) is correct.
Type C : Programming Practice
Type C : Programming practice
1Write a program to obtain principal amount , rate of interest and time from user and compute
simple interest.
principal = int(input("enter principal amount = "))
rate = int(input("enter rate = "))
time = int(input("enter time = "))
si = principal * rate * time / 100
print("simple interest = ",si)
2 .Write a program to obtain temperature of 7 days (Monday….sunday)
a = int(input("enter the 1st day temperature = "))
b = int(input("enter the 2nd day temperature = "))
c = int(input("enter the 3rd day temperature = "))
d = int(input("enter the 4th day temperature = "))
e = int(input("enter the 5th day temperature = "))
f = int(input("enter the 6th day temperature = "))
g = int(input("enter the 7th day temperature = "))
average = (a + b+ c + d +e + f + g )/7
print("average of temperature = ",average ,"C")
3. Write a program to obtain x, y, z from the user and calculate expression: 4x4 +3y3+9z+6p
x = int(input("enter first number = "))
y = int(input("enter second number = "))
z = int(input("enter third number = "))
expression = (4*x**4)+(3*y**3)+(9*z)+(6*3.14)
print ("value = ",expression)
4. Write a program that reads a number of seconds and print it in form : mins And second ,
eg ,
200 second are printed as 3 mins and 20 second.
time= int(input("enter the time in second = "))
min = time // 60
second = time%60
print("time = ",min,"mins",second,"second ")
5. Write a program to take year as input and check if it is leap year or not.
year = int(input("enter year = "))
print((year % 4 == 0 and "it is leap year ")or "it is not leap year")
6. Write a program to take two numbers and print if the first number is fully divisible by second
number or not.
a = int(input("enter the number = "))
b = int(input("enter the divisor = "))
print((a%b == 0 and "it is divisible ") or "it is not divisible" )
7. Write a program to take a two digit number and then print the reversed number .
a = int(input("enter a two digit number = "))
b = a // 10
c = a% 10
print("number in reverse order = ", c , b )
8. Try writing program (similar to previous one ) for three digit number i.e. , if you input 123 ,
the program should print 321
a = int(input("enter a three digit number = "))
b = a // 10
c= b // 10
d = b % 10
e = a % 10
print("number in reverse order = ",e,d,c)
9. Write a program to take two inputs for day, month and then calculate which day of the year,
the given date is .for simplicity; take 30 days for all month.
For example:
If you give input as: day = 3, month = 2
Then it should print “day of the year: 33”.
day = int(input("enter the date = "))
month = int(input("enter the month = "))
print("number of total days in year = ",30*(month -1 )+day)
Write a program that asks a user for a number of years, and then prints out the number of days,
hours, minutes and seconds in that number of years.
How many years? 10
10.0 years is:
3650.0 days
87600.0 hours
5256800:0 minutes
315360000.0 seconds
year = int (input ( "How many years?" ) )
print (year,"years is:")
print (365*year, "days")
print (24*365*year, "hours")
print (60*24*365*year, "minutes")
print (60*60*24*365*year, "seconds")
Write a program that inputs an age and print age after 10 years as shown below:
What is your age? 17
In ten years, you will be 27 years old!
age = int (input ("What is your age?" ) )
print ("In ten years, you will be", age + 10 , "years old!")
Write a program whose three sample runs are shown below:
Sample Run 1
Random number between 0 and 5 (A): 2
Random number between 0 and 5 (B): 5.
A to the power = 32
Sample Run 2
Random number between o and 5 (A): 4
Random number between 0 and 5 (B): 3.
A to the power = 64
Sample Run 3
Random number between 0 and 5 (A): 1
Random number between 0 and 5 (B): 1.
A to the power =1
import random
a = random.randint(0,5)
b = random.randint(0,5)
print("Random number between 0 and 5 (A): ",a)
print("Random number between 0 and 5 (B): ",b)
print("A to the power = ", a**b)
Write a program that generates six random numbers in a sequence created with (start, stop, step).
Then print the mean, median and mode of the generated numbers.
import random
import statistics
start = int(input("Enter Start :-"))
stop = int(input("Enter stop :- "))
step = int(input("Enter step :- "))
a = random.randrange(start,stop,step)
b = random.randrange(start,stop,step)
c = random.randrange(start,stop,step)
d = random.randrange(start,stop,step)
e = random.randrange(start,stop,step)
f = random.randrange(start,stop,step)
print( "Numbers are =",a,b,c,d,e,f )
print("Mean = ", statistics.mean( a,b,c,d,e,f ) )
print("Mode = ", statistics.mode( a,b,c,d,e,f ) )
print("Median =", statistics.median( a,b,c,d,e,f ) )
Write a program to generate 3 random integers between 100 and 999 which is divisible by 5.
import random
count = 1
while count <= 3 :
num = random.randint(100,999)
if num % 5 == 0 :
print (num)
count += 1
Write a program to generate 6 digit random secure OTP between 100000 to 999999.
import random
count = 1
while count <= 6 :
num = random.randint(100000,999999)
print("OTP =",num)
count += 1
Write a program to generate 6 random numbers and then print their mean, median and mode.
import random
print("OTP" , random.randint(100000,999999) )
print("OTP" , random.randint(100000,999999) )
print("OTP" , random.randint(100000,999999) )
print("OTP" , random.randint(100000,999999) )
print("OTP" , random.randint(100000,999999) )
print("OTP" , random.randint(100000,999999) )
Write a program to find a side of a right angled triangle who’s two sides and an angle is given.
side1 = int(input("Enter side one :"))
side2 = int(input("Enter side two :"))
angle = int(input("Enter the angle :")) #Angle is not require to solve this Question
print("Biggest side :-" , (side1**2 + side2**2 )**0.5 )
Write a program to calculate the radius of a sphere whose area (4πr2) is given.
area = int(input("Enter the area :-"))
radius = ( area / (4 * 3.14 ) ) **0.5
print("Radius =", radius)
Write a program that inputs a string and then prints it equal to number of times its length.
e.g.
Enter string : "eka"
Result ekaekaeka
str = input("Enter string: ")
len = len(str)
opStr = str * len
print("Result", opStr)
Find the volume of the cylinder as shown:
Who’s radius is 6cm and height is 15cm.
r=6
h = 15
print( "Volume of cylender :-" , 3.14 * r ** 2 * h )
Write a program to calculate the area of an equilateral triangle.
side = int (input("Enter side :- "))
area = ( 3**0.5 / 2 ) * side * side
print("Area = ", area)
Write a program to input the radius of a sphere and calculate its volume.
Answer =
rad = int (input("Enter the radius :-"))
volume = (4/3) * 3.14 * rad ** 3
print ("Volume = ", volume)
Output:-
(a)
Enter the radius :-7
Volume = 1436.0266666666666
>>>
(b)
Enter the radius :-12
Volume = 7234.5599999999995
>>>
(c)
Enter the radius :-16
Volume = 17148.586666666666
>>>
Write a program to calculate amount payable after simple interest.
p = float(input("Enter principal amount :-"))
r = float(input("Enter Rate :-"))
t = int(input("Enter time :-"))
si = (p * r * t ) /100
print("amount payable =" , si + p )
Write a program to calculate amount payable after compound interest.
p = float(input("Enter principal amount :-"))
r = float(input("Enter Rate :-"))
t = int(input("Enter time :-"))
com = p * ( (1 + (r / 100 ))** t ) - p
print("amount payable =" , com + p )
Write a program to computer (a + b)3 using the formula a3 + b3 +3a²b+3ab2?
a = int(input("Enter a :-"))
b = int(input("Enetr b :-"))
formula = a ** 3 + b ** 3 + 3 * (a ** 2) * b + 3 * a * (b ** 2)
print(formula)